<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Chapter 3 Mutational signature analysis basics | Extract, Analyze and Visualize Mutational Signatures with Sigminer</title>
<meta name="author" content="Shixiang Wang, PhD (Sun Yat-sen University Cancer Center)">
<meta name="author" content="Xue-Song Liu, PhD (ShanghaiTech University)">
<meta name="description" content="This chapter demonstrates how to run two key mutational signature analyses (de novo signature discovery and signature fitting) in details. More specifically, we will introduce how to identify...">
<meta name="generator" content="bookdown 0.28 with bs4_book()">
<meta property="og:title" content="Chapter 3 Mutational signature analysis basics | Extract, Analyze and Visualize Mutational Signatures with Sigminer">
<meta property="og:type" content="book">
<meta property="og:description" content="This chapter demonstrates how to run two key mutational signature analyses (de novo signature discovery and signature fitting) in details. More specifically, we will introduce how to identify...">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Chapter 3 Mutational signature analysis basics | Extract, Analyze and Visualize Mutational Signatures with Sigminer">
<meta name="twitter:description" content="This chapter demonstrates how to run two key mutational signature analyses (de novo signature discovery and signature fitting) in details. More specifically, we will introduce how to identify...">
<!-- JS --><script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.6/clipboard.min.js" integrity="sha256-inc5kl9MA1hkeYUt+EC3BhlIgyp/2jDIyBLS6k3UxPI=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/fuse.js/6.4.6/fuse.js" integrity="sha512-zv6Ywkjyktsohkbp9bb45V6tEMoWhzFzXis+LrMehmJZZSys19Yxf1dopHx7WzIKxr5tK2dVcYmaCk2uqdjF4A==" crossorigin="anonymous"></script><script src="https://kit.fontawesome.com/6ecbd6c532.js" crossorigin="anonymous"></script><script src="libs/jquery-3.6.0/jquery-3.6.0.min.js"></script><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link href="libs/bootstrap-4.6.0/bootstrap.min.css" rel="stylesheet">
<script src="libs/bootstrap-4.6.0/bootstrap.bundle.min.js"></script><script src="libs/bs3compat-0.4.0/transition.js"></script><script src="libs/bs3compat-0.4.0/tabs.js"></script><script src="libs/bs3compat-0.4.0/bs3compat.js"></script><link href="libs/bs4_book-1.0.0/bs4_book.css" rel="stylesheet">
<script src="libs/bs4_book-1.0.0/bs4_book.js"></script><script src="libs/htmlwidgets-1.5.4/htmlwidgets.js"></script><link href="libs/datatables-css-0.0.0/datatables-crosstalk.css" rel="stylesheet">
<script src="libs/datatables-binding-0.24/datatables.js"></script><link href="libs/dt-core-1.11.3/css/jquery.dataTables.min.css" rel="stylesheet">
<link href="libs/dt-core-1.11.3/css/jquery.dataTables.extra.css" rel="stylesheet">
<script src="libs/dt-core-1.11.3/js/jquery.dataTables.min.js"></script><link href="libs/crosstalk-1.2.0/css/crosstalk.min.css" rel="stylesheet">
<script src="libs/crosstalk-1.2.0/js/crosstalk.min.js"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/autocomplete.js/0.38.0/autocomplete.jquery.min.js" integrity="sha512-GU9ayf+66Xx2TmpxqJpliWbT5PiGYxpaG8rfnBEk1LL8l1KGkRShhngwdXK1UgqhAzWpZHSiYPc09/NwDQIGyg==" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/mark.js/8.11.1/mark.min.js" integrity="sha512-5CYOlHXGh6QpOFA/TeTylKLWfB3ftPsde7AnmhuitiTX4K5SqCLBeKro6sPS8ilsz1Q4NRx3v8Ko2IBiszzdww==" crossorigin="anonymous"></script><!-- CSS --><style type="text/css">
    
    div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
  </style>
<style type="text/css">
    /* Used with Pandoc 2.11+ new --citeproc when CSL is used */
    div.csl-bib-body { }
    div.csl-entry {
      clear: both;
        }
    .hanging div.csl-entry {
      margin-left:2em;
      text-indent:-2em;
    }
    div.csl-left-margin {
      min-width:2em;
      float:left;
    }
    div.csl-right-inline {
      margin-left:2em;
      padding-left:1em;
    }
    div.csl-indent {
      margin-left: 2em;
    }
  </style>
</head>
<body data-spy="scroll" data-target="#toc">

<div class="container-fluid">
<div class="row">
  <header class="col-sm-12 col-lg-3 sidebar sidebar-book"><a class="sr-only sr-only-focusable" href="#content">Skip to main content</a>

    <div class="d-flex align-items-start justify-content-between">
      <h1>
        <a href="index.html" title="">Extract, Analyze and Visualize Mutational Signatures with Sigminer</a>
      </h1>
      <button class="btn btn-outline-primary d-lg-none ml-2 mt-1" type="button" data-toggle="collapse" data-target="#main-nav" aria-expanded="true" aria-controls="main-nav"><i class="fas fa-bars"></i><span class="sr-only">Show table of contents</span></button>
    </div>

    <div id="main-nav" class="collapse-lg">
      <form role="search">
        <input id="search" class="form-control" type="search" placeholder="Search" aria-label="Search">
</form>

      <nav aria-label="Table of contents"><h2>Table of contents</h2>
        <ul class="book-toc list-unstyled">
<li><a class="" href="index.html">📖 Introduction</a></li>
<li class="book-part">Part I: Background and Prerequisite</li>
<li><a class="" href="mutsig-intro.html"><span class="header-section-number">1</span> Mutational signatures</a></li>
<li><a class="" href="prerequisite.html"><span class="header-section-number">2</span> Package prerequisite and installation</a></li>
<li class="book-part">Part II: Workflows</li>
<li><a class="active" href="basic-workflow.html"><span class="header-section-number">3</span> Mutational signature analysis basics</a></li>
<li><a class="" href="analysis-supps.html"><span class="header-section-number">4</span> Other signature types</a></li>
<li><a class="" href="target-vis.html"><span class="header-section-number">5</span> Target visualization</a></li>
<li class="book-part">Part III: Miscellaneous topics</li>
<li><a class="" href="universal-analysis.html"><span class="header-section-number">6</span> Universal analysis</a></li>
<li><a class="" href="subtype-prediction.html"><span class="header-section-number">7</span> Subtype prediction</a></li>
<li><a class="" href="sigflow.html"><span class="header-section-number">8</span> Sigflow pipeline</a></li>
<li><a class="" href="datasets.html"><span class="header-section-number">9</span> Datasets</a></li>
<li><a class="" href="convert.html"><span class="header-section-number">10</span> SBS signature conversion</a></li>
<li class="book-part">Appendix</li>
<li><a class="" href="references.html">References</a></li>
</ul>

        <div class="book-extra">
          
        </div>
      </nav>
</div>
  </header><main class="col-sm-12 col-md-9 col-lg-7" id="content"><div id="basic-workflow" class="section level1" number="3">
<h1>
<span class="header-section-number">3</span> Mutational signature analysis basics<a class="anchor" aria-label="anchor" href="#basic-workflow"><i class="fas fa-link"></i></a>
</h1>
<p>This chapter demonstrates how to run two key mutational signature analyses (<em>de novo</em> signature
discovery and signature fitting) in details.
More specifically, we will introduce how to identify COSMIC signatures from records of variant calling data.
The COSMIC signatures include three type of signatures: SBS, DBS and ID (short for INDEL). For other signature type, please read chapter <a href="analysis-supps.html#analysis-supps">4</a>.</p>
<p>The signature identification procedure has been divided into 3 steps:</p>
<ol style="list-style-type: decimal">
<li>Read mutation data.</li>
<li>Tally components: for SBS, it means classifying SBS records into 96 components (the most common case) and generating sample matrix by counting component in each sample.</li>
<li>
<em>de novo</em> extract signatures or quantify signature activity by fitting observed
data to reference signature.</li>
</ol>
<ul>
<li>For <em>de novo</em> signature discovery, there are manual approach and automatic approach. When you choose manual approach, you should estimate signature number and then extract specified number of signatures.</li>
</ul>
<div id="data-input" class="section level2" number="3.1">
<h2>
<span class="header-section-number">3.1</span> Data input<a class="anchor" aria-label="anchor" href="#data-input"><i class="fas fa-link"></i></a>
</h2>
<p>The input data should be in <a href="https://www.ebi.ac.uk/training-beta/online/courses/human-genetic-variation-introduction/variant-identification-and-analysis/understanding-vcf-format/">VCF</a>, <a href="https://docs.gdc.cancer.gov/Data/File_Formats/MAF_Format/">MAF</a> format.</p>
<ul>
<li>For VCF, it can only be VCF file paths.</li>
<li>For MAF, it can be either a MAF file or a <code>data.frame</code>.</li>
</ul>
<p>MAF format is the standard way to represent small-scale variants in <strong>sigminer</strong>. There is a popular R/Bioconductor package <a href="https://github.com/PoisonAlien/maftools"><strong>maftools</strong></a> <span class="citation">(<a href="references.html#ref-mayakonda2018maftools" role="doc-biblioref">Mayakonda et al. 2018</a>)</span> for analyzing MAF data. It provides an R class <strong>MAF</strong> to represent MAF format data.</p>
<div id="vcf-as-input" class="section level3" number="3.1.1">
<h3>
<span class="header-section-number">3.1.1</span> VCF as input<a class="anchor" aria-label="anchor" href="#vcf-as-input"><i class="fas fa-link"></i></a>
</h3>
<p>If you use VCF files as input, you can use <code><a href="https://rdrr.io/pkg/sigminer/man/read_vcf.html">read_vcf()</a></code> to read multiple VCF files as a <code>MAF</code> object.</p>
<div class="sourceCode" id="cb7"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="kw"><a href="https://rdrr.io/r/base/library.html">library</a></span><span class="op">(</span><span class="va"><a href="https://github.com/ShixiangWang/sigminer">sigminer</a></span><span class="op">)</span></span>
<span></span>
<span><span class="va">vcfs</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/list.files.html">list.files</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/system.file.html">system.file</a></span><span class="op">(</span><span class="st">"extdata"</span>, package <span class="op">=</span> <span class="st">"sigminer"</span><span class="op">)</span>, <span class="st">"*.vcf"</span>, full.names <span class="op">=</span> <span class="cn">TRUE</span><span class="op">)</span></span>
<span><span class="va">maf</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/pkg/sigminer/man/read_vcf.html">read_vcf</a></span><span class="op">(</span><span class="va">vcfs</span><span class="op">)</span></span>
<span><span class="co">## Reading file(s): /Users/wsx/Library/R/sigminer/extdata/test1.vcf, /Users/wsx/Library/R/sigminer/extdata/test2.vcf, /Users/wsx/Library/R/sigminer/extdata/test3.vcf</span></span>
<span><span class="co">## It seems /Users/wsx/Library/R/sigminer/extdata/test2.vcf has no normal VCF header, try parsing without header.</span></span>
<span><span class="co">## Annotating Variant Type...</span></span>
<span><span class="co">## Downloading https://zenodo.org/record/4771552/files/human_hg19_gene_info.rds to /Users/wsx/Library/R/sigminer/extdata/human_hg19_gene_info.rds</span></span>
<span><span class="co">## Annotating mutations to first matched gene based on database /Users/wsx/Library/R/sigminer/extdata/human_hg19_gene_info.rds...</span></span>
<span><span class="co">## Transforming into a MAF object...</span></span>
<span><span class="co">## -Validating</span></span>
<span><span class="co">## --Non MAF specific values in Variant_Classification column:</span></span>
<span><span class="co">##   Unknown</span></span>
<span><span class="co">## -Summarizing</span></span>
<span><span class="co">## -Processing clinical data</span></span>
<span><span class="co">## --Missing clinical data</span></span>
<span><span class="co">## -Finished in 0.033s elapsed (0.032s cpu)</span></span>
<span><span class="va">maf</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/pkg/sigminer/man/read_vcf.html">read_vcf</a></span><span class="op">(</span><span class="va">vcfs</span>, keep_only_pass <span class="op">=</span> <span class="cn">FALSE</span><span class="op">)</span></span>
<span><span class="co">## Reading file(s): /Users/wsx/Library/R/sigminer/extdata/test1.vcf, /Users/wsx/Library/R/sigminer/extdata/test2.vcf, /Users/wsx/Library/R/sigminer/extdata/test3.vcf</span></span>
<span><span class="co">## It seems /Users/wsx/Library/R/sigminer/extdata/test2.vcf has no normal VCF header, try parsing without header.</span></span>
<span><span class="co">## Annotating Variant Type...</span></span>
<span><span class="co">## Annotating mutations to first matched gene based on database /Users/wsx/Library/R/sigminer/extdata/human_hg19_gene_info.rds...</span></span>
<span><span class="co">## Transforming into a MAF object...</span></span>
<span><span class="co">## -Validating</span></span>
<span><span class="co">## --Non MAF specific values in Variant_Classification column:</span></span>
<span><span class="co">##   Unknown</span></span>
<span><span class="co">## -Summarizing</span></span>
<span><span class="co">## -Processing clinical data</span></span>
<span><span class="co">## --Missing clinical data</span></span>
<span><span class="co">## -Finished in 0.025s elapsed (0.024s cpu)</span></span></code></pre></div>
</div>
<div id="maf-as-input" class="section level3" number="3.1.2">
<h3>
<span class="header-section-number">3.1.2</span> MAF as input<a class="anchor" aria-label="anchor" href="#maf-as-input"><i class="fas fa-link"></i></a>
</h3>
<p>MAF format is the most recommended input, you can provide it either as a file or as a <code>data.frame</code>.</p>
<p>Typically, you can obtain the data in the following ways:</p>
<ol style="list-style-type: decimal">
<li>You get multiple VCF files and convert them into a MAF file (<a href="https://github.com/mskcc/vcf2maf">vcf2maf</a> is the most used tool for conversion).</li>
<li>You get a MAF file from a reference or a public data portal, e.g., <a href="http://www.cbioportal.org/">cBioPortal</a> or <a href="https://portal.gdc.cancer.gov/">GDC portal</a>.</li>
<li>You get a EXCEL file providing MAF-like data from a reference, you should read the data firstly (with <code><a href="https://readxl.tidyverse.org/reference/read_excel.html">readxl::read_excel()</a></code>) and then construct a <code>data.frame</code> providing necessary columns.</li>
</ol>
<p>Once a MAF file or a MAF-like <code>data.frame</code> is ready, you can read/convert it as a <code>MAF</code> object with <code><a href="https://rdrr.io/pkg/sigminer/man/read_maf.html">read_maf()</a></code>. Here TCGA LAML dataset is used as an example:</p>
<div class="sourceCode" id="cb8"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="va">laml.maf</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/system.file.html">system.file</a></span><span class="op">(</span><span class="st">"extdata"</span>, <span class="st">"tcga_laml.maf.gz"</span>, package <span class="op">=</span> <span class="st">"maftools"</span>, mustWork <span class="op">=</span> <span class="cn">TRUE</span><span class="op">)</span></span>
<span><span class="va">laml</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/pkg/sigminer/man/read_maf.html">read_maf</a></span><span class="op">(</span>maf <span class="op">=</span> <span class="va">laml.maf</span><span class="op">)</span></span>
<span><span class="co">## -Reading</span></span>
<span><span class="co">## -Validating</span></span>
<span><span class="co">## -Silent variants: 475 </span></span>
<span><span class="co">## -Summarizing</span></span>
<span><span class="co">## -Processing clinical data</span></span>
<span><span class="co">## --Missing clinical data</span></span>
<span><span class="co">## -Finished in 0.295s elapsed (0.271s cpu)</span></span>
<span><span class="va">laml</span></span>
<span><span class="co">## An object of class  MAF </span></span>
<span><span class="co">##                    ID          summary  Mean Median</span></span>
<span><span class="co">##  1:        NCBI_Build               37    NA     NA</span></span>
<span><span class="co">##  2:            Center genome.wustl.edu    NA     NA</span></span>
<span><span class="co">##  3:           Samples              193    NA     NA</span></span>
<span><span class="co">##  4:            nGenes             1241    NA     NA</span></span>
<span><span class="co">##  5:   Frame_Shift_Del               52 0.269      0</span></span>
<span><span class="co">##  6:   Frame_Shift_Ins               91 0.472      0</span></span>
<span><span class="co">##  7:      In_Frame_Del               10 0.052      0</span></span>
<span><span class="co">##  8:      In_Frame_Ins               42 0.218      0</span></span>
<span><span class="co">##  9: Missense_Mutation             1342 6.953      7</span></span>
<span><span class="co">## 10: Nonsense_Mutation              103 0.534      0</span></span>
<span><span class="co">## 11:       Splice_Site               92 0.477      0</span></span>
<span><span class="co">## 12:             total             1732 8.974      9</span></span></code></pre></div>
<p>The <code>laml</code> is a <code>MAF</code> object. The <code>MAF</code> class is exported from <strong>maftools</strong> to <strong>sigminer</strong>. So <code>laml</code> can be directly use functions provided by <strong>maftools</strong>.</p>
<p>As a <code>MAF</code> object, the mutation records are stored in slot <code>data</code> and <code>maf.silent</code>.</p>
<div class="sourceCode" id="cb9"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="fu"><a href="https://rdrr.io/r/utils/head.html">head</a></span><span class="op">(</span><span class="va">laml</span><span class="op">@</span><span class="va">data</span><span class="op">)</span></span>
<span><span class="co">##    Hugo_Symbol Entrez_Gene_Id           Center NCBI_Build Chromosome</span></span>
<span><span class="co">## 1:      ABCA10          10349 genome.wustl.edu         37         17</span></span>
<span><span class="co">## 2:       ABCA4             24 genome.wustl.edu         37          1</span></span>
<span><span class="co">## 3:      ABCB11           8647 genome.wustl.edu         37          2</span></span>
<span><span class="co">## 4:       ABCC3           8714 genome.wustl.edu         37         17</span></span>
<span><span class="co">## 5:       ABCF1             23 genome.wustl.edu         37          6</span></span>
<span><span class="co">## 6:       ABCG4          64137 genome.wustl.edu         37         11</span></span>
<span><span class="co">##    Start_Position End_Position Strand Variant_Classification Variant_Type</span></span>
<span><span class="co">## 1:       67170917     67170917      +            Splice_Site          SNP</span></span>
<span><span class="co">## 2:       94490594     94490594      +      Missense_Mutation          SNP</span></span>
<span><span class="co">## 3:      169780250    169780250      +      Missense_Mutation          SNP</span></span>
<span><span class="co">## 4:       48760974     48760974      +      Missense_Mutation          SNP</span></span>
<span><span class="co">## 5:       30554429     30554429      +      Missense_Mutation          SNP</span></span>
<span><span class="co">## 6:      119031351    119031351      +      Missense_Mutation          SNP</span></span>
<span><span class="co">##    Reference_Allele Tumor_Seq_Allele1 Tumor_Seq_Allele2 Tumor_Sample_Barcode</span></span>
<span><span class="co">## 1:                T                 T                 C         TCGA-AB-2988</span></span>
<span><span class="co">## 2:                C                 C                 T         TCGA-AB-2869</span></span>
<span><span class="co">## 3:                G                 G                 A         TCGA-AB-3009</span></span>
<span><span class="co">## 4:                C                 C                 T         TCGA-AB-2887</span></span>
<span><span class="co">## 5:                G                 G                 A         TCGA-AB-2920</span></span>
<span><span class="co">## 6:                A                 A                 G         TCGA-AB-2934</span></span>
<span><span class="co">##    Protein_Change i_TumorVAF_WU i_transcript_name</span></span>
<span><span class="co">## 1:        p.K960R      45.66000       NM_080282.3</span></span>
<span><span class="co">## 2:       p.R1517H      38.12000       NM_000350.2</span></span>
<span><span class="co">## 3:       p.A1283V      46.97218       NM_003742.2</span></span>
<span><span class="co">## 4:       p.P1271S      56.41000       NM_003786.1</span></span>
<span><span class="co">## 5:        p.G658S      40.95000    NM_001025091.1</span></span>
<span><span class="co">## 6:        p.Y567C      32.84000       NM_022169.1</span></span>
<span><span class="fu"><a href="https://rdrr.io/r/utils/head.html">head</a></span><span class="op">(</span><span class="va">laml</span><span class="op">@</span><span class="va">maf.silent</span><span class="op">)</span></span>
<span><span class="co">##    Hugo_Symbol Entrez_Gene_Id           Center NCBI_Build Chromosome</span></span>
<span><span class="co">## 1:      ABCC11          85320 genome.wustl.edu         37         16</span></span>
<span><span class="co">## 2:        ACAN            176 genome.wustl.edu         37         15</span></span>
<span><span class="co">## 3:       ACAT1             38 genome.wustl.edu         37         11</span></span>
<span><span class="co">## 4:       ACCN2             41 genome.wustl.edu         37         12</span></span>
<span><span class="co">## 5:       ACTA2             59 genome.wustl.edu         37         10</span></span>
<span><span class="co">## 6:       ACTL9         284382 genome.wustl.edu         37         19</span></span>
<span><span class="co">##    Start_Position End_Position Strand Variant_Classification Variant_Type</span></span>
<span><span class="co">## 1:       48244997     48244997      +                 Silent          SNP</span></span>
<span><span class="co">## 2:       89401084     89401084      +                 Silent          SNP</span></span>
<span><span class="co">## 3:      108009744    108009744      +                 Silent          SNP</span></span>
<span><span class="co">## 4:       50452780     50452780      +                 Silent          SNP</span></span>
<span><span class="co">## 5:       90695109     90695109      +                 Silent          SNP</span></span>
<span><span class="co">## 6:        8808551      8808551      +                 Silent          SNP</span></span>
<span><span class="co">##    Reference_Allele Tumor_Seq_Allele1 Tumor_Seq_Allele2 Tumor_Sample_Barcode</span></span>
<span><span class="co">## 1:                G                 G                 A         TCGA-AB-2830</span></span>
<span><span class="co">## 2:                C                 C                 T         TCGA-AB-2898</span></span>
<span><span class="co">## 3:                T                 T                 G         TCGA-AB-2887</span></span>
<span><span class="co">## 4:                C                 C                 G         TCGA-AB-3009</span></span>
<span><span class="co">## 5:                C                 C                 T         TCGA-AB-2973</span></span>
<span><span class="co">## 6:                G                 G                 A         TCGA-AB-2936</span></span>
<span><span class="co">##    Protein_Change i_TumorVAF_WU i_transcript_name</span></span>
<span><span class="co">## 1:        p.I490I    34.2700000       NM_032583.3</span></span>
<span><span class="co">## 2:       p.S1756S    38.3000000       NM_013227.2</span></span>
<span><span class="co">## 3:        p.T185T    49.0400000       NM_000019.3</span></span>
<span><span class="co">## 4:         p.L77L    48.1000000       NM_020039.2</span></span>
<span><span class="co">## 5:        p.P335P     0.2012072       NM_001613.1</span></span>
<span><span class="co">## 6:        p.F167F    46.1500000       NM_178525.3</span></span></code></pre></div>
<p>The <code>data</code> slot contains non-silent variants, and the <code>maf.silent</code> slot contains silent variants.
Default uses “Variant Classifications” with high/moderate variant consequences as non-silent variants. <a href="http://asia.ensembl.org/Help/Glossary?id=535" class="uri">http://asia.ensembl.org/Help/Glossary?id=535</a>: “Frame_Shift_Del”, “Frame_Shift_Ins”, “Splice_Site”, “Translation_Start_Site”,“Nonsense_Mutation”, “Nonstop_Mutation”, “In_Frame_Del”,“In_Frame_Ins”, “Missense_Mutation” (see <code><a href="https://rdrr.io/pkg/sigminer/man/read_maf.html">?read_maf</a></code>). If you want to change, please set <code>vc_nonSyn</code> option.</p>
<p>Other slots in <code>MAF</code> object are summary data either by sample or gene/variant type etc.</p>
<div class="sourceCode" id="cb10"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="fu">slotNames</span><span class="op">(</span><span class="va">laml</span><span class="op">)</span></span>
<span><span class="co">## [1] "data"                           "variants.per.sample"           </span></span>
<span><span class="co">## [3] "variant.type.summary"           "variant.classification.summary"</span></span>
<span><span class="co">## [5] "gene.summary"                   "summary"                       </span></span>
<span><span class="co">## [7] "maf.silent"                     "clinical.data"</span></span></code></pre></div>
<p>Acute myeloid leukemia is not a good object to study mutational signatures due to low mutation burden, we will use a subset of TCGA breast cohort as for illustration of the following analyses.</p>
<p>Anand Mayakonda has already stored whole TCGA mutation data as MAF objects in <a href="https://github.com/PoisonAlien/TCGAmutations"><strong>TCGAmutations</strong></a> package.
Here I will load the TCGA BRCA cohort and create a sub-cohort with 100 tumors.</p>
<div class="sourceCode" id="cb11"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="kw"><a href="https://rdrr.io/r/base/library.html">library</a></span><span class="op">(</span><span class="va"><a href="https://github.com/PoisonAlien/maftools">maftools</a></span><span class="op">)</span></span>
<span><span class="fu"><a href="https://rdrr.io/pkg/maftools/man/tcgaAvailable.html">tcgaAvailable</a></span><span class="op">(</span><span class="op">)</span></span></code></pre></div>
<div class="sourceCode" id="cb12"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="fu"><a href="https://rdrr.io/r/base/Random.html">set.seed</a></span><span class="op">(</span><span class="fl">1234</span><span class="op">)</span></span>
<span><span class="co"># brca &lt;- readRDS("data/BRCA.RDs")</span></span>
<span><span class="va">brca</span> <span class="op">&lt;-</span> <span class="fu">tcga_load</span><span class="op">(</span><span class="st">"BRCA"</span><span class="op">)</span></span>
<span><span class="va">brca</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/pkg/maftools/man/subsetMaf.html">subsetMaf</a></span><span class="op">(</span><span class="va">brca</span>,</span>
<span>  tsb <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/character.html">as.character</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/sample.html">sample</a></span><span class="op">(</span><span class="va">brca</span><span class="op">@</span><span class="va">variants.per.sample</span><span class="op">$</span><span class="va">Tumor_Sample_Barcode</span>, <span class="fl">100</span><span class="op">)</span><span class="op">)</span></span>
<span><span class="op">)</span></span>
<span><span class="fu"><a href="https://rdrr.io/r/base/readRDS.html">saveRDS</a></span><span class="op">(</span><span class="va">brca</span>, file <span class="op">=</span> <span class="st">"data/brca.rds"</span><span class="op">)</span></span></code></pre></div>
<blockquote>
<p>Here we save this cohort so no need to download the dataset every time.</p>
</blockquote>
<div class="sourceCode" id="cb13"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="va">brca</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/readRDS.html">readRDS</a></span><span class="op">(</span><span class="st">"data/brca.rds"</span><span class="op">)</span></span></code></pre></div>
<p>For CNV and genome rearrangement records, check chapter <a href="analysis-supps.html#analysis-supps">4</a>.</p>
</div>
</div>
<div id="tally-components" class="section level2" number="3.2">
<h2>
<span class="header-section-number">3.2</span> Tally components<a class="anchor" aria-label="anchor" href="#tally-components"><i class="fas fa-link"></i></a>
</h2>
<div id="the-most-common-96-components" class="section level3" number="3.2.1">
<h3>
<span class="header-section-number">3.2.1</span> The most common 96 components<a class="anchor" aria-label="anchor" href="#the-most-common-96-components"><i class="fas fa-link"></i></a>
</h3>
<p>According to 3-nucleotide context (mutated base, 5’ and 3’ adjacent bases) and base complementary pairing principle, we can divide all SBS mutations into 96 mutation types. We call each mutation type as a <em>component</em> here.</p>
<blockquote>
<p>This classification is based the six substitution subtypes: C&gt;A, C&gt;G, C&gt;T, T&gt;A, T&gt;C, and T&gt;G (all substitutions are referred to by the pyrimidine of the mutated Watson—Crick base pair). Further, each of the substitutions is examined by incorporating information on the bases immediately 5’ and 3’ to each mutated base generating 96 possible mutation types (6 types of substitution x 4 types of 5’ base x 4 types of 3’ base).</p>
</blockquote>
<div class="figure">
<span style="display:block;" id="fig:unnamed-chunk-22"></span>
<img src="fig/MutationTypes_v3.jpg" alt="The illustration of 96 components, fig source: https://en.wikipedia.org/wiki/Mutational_signatures" width="95%"><p class="caption">
Figure 3.1: The illustration of 96 components, fig source: <a href="https://en.wikipedia.org/wiki/Mutational_signatures" class="uri">https://en.wikipedia.org/wiki/Mutational_signatures</a>
</p>
</div>
<p>We tally components in each sample, and generate a sample-by-component matrix.</p>
<div class="sourceCode" id="cb14"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="va">mt_tally</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/pkg/sigminer/man/sig_tally.html">sig_tally</a></span><span class="op">(</span></span>
<span>  <span class="va">brca</span>,</span>
<span>  ref_genome <span class="op">=</span> <span class="st">"BSgenome.Hsapiens.UCSC.hg19"</span>,</span>
<span>  use_syn <span class="op">=</span> <span class="cn">TRUE</span></span>
<span><span class="op">)</span></span>
<span><span class="co">## ℹ [2021-12-04 23:49:57]: Started.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:50:06]: We would assume you marked all variants' position in + strand.</span></span>
<span><span class="co">## </span></span>
<span><span class="co">## Attaching package: 'S4Vectors'</span></span>
<span><span class="co">## The following objects are masked from 'package:base':</span></span>
<span><span class="co">## </span></span>
<span><span class="co">##     expand.grid, I, unname</span></span>
<span><span class="co">## </span></span>
<span><span class="co">## Attaching package: 'Biostrings'</span></span>
<span><span class="co">## The following object is masked from 'package:base':</span></span>
<span><span class="co">## </span></span>
<span><span class="co">##     strsplit</span></span>
<span><span class="co">## ✓ [2021-12-04 23:50:06]: Reference genome loaded.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:50:06]: Variants from MAF object queried.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:50:06]: Chromosome names checked.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:50:06]: Sex chromosomes properly handled.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:50:06]: Only variants located in standard chromosomes (1:22, X, Y, M/MT) are kept.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:50:06]: Variant start and end position checked.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:50:06]: Variant data for matrix generation preprocessed.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:50:06]: SBS matrix generation - start.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:50:06]: Extracting 5' and 3' adjacent bases.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:50:09]: Extracting +/- 20bp around mutated bases for background C&gt;T estimation.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:50:09]: Estimating APOBEC enrichment scores.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:50:09]: Performing one-way Fisher's test for APOBEC enrichment.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:50:10]: APOBEC related mutations are enriched in 28% of samples (APOBEC enrichment score &gt; 2; 28 of 100 samples)</span></span>
<span><span class="co">## ℹ [2021-12-04 23:50:10]: Creating SBS sample-by-component matrices.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:50:10]: SBS-6 matrix created.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:50:10]: SBS-96 matrix created.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:50:10]: SBS-1536 matrix created.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:50:10]: Return SBS-96 as major matrix.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:50:10]: Done.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:50:10]: 12.54 secs elapsed.</span></span></code></pre></div>
<blockquote>
<p>Here set <code>use_syn = TRUE</code> to include all variant records in MAF object to generate sample matrix.</p>
</blockquote>
<div class="sourceCode" id="cb15"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="va">mt_tally</span><span class="op">$</span><span class="va">nmf_matrix</span><span class="op">[</span><span class="fl">1</span><span class="op">:</span><span class="fl">5</span>, <span class="fl">1</span><span class="op">:</span><span class="fl">5</span><span class="op">]</span></span>
<span><span class="co">##                              A[T&gt;C]A C[T&gt;C]A G[T&gt;C]A T[T&gt;C]A A[C&gt;T]A</span></span>
<span><span class="co">## TCGA-A1-A0SH-01A-11D-A099-09       0       0       1       1       0</span></span>
<span><span class="co">## TCGA-A2-A04N-01A-11D-A10Y-09       0       0       0       1       2</span></span>
<span><span class="co">## TCGA-A2-A0CP-01A-11W-A050-09       0       0       0       0       0</span></span>
<span><span class="co">## TCGA-A2-A0EP-01A-52D-A22X-09       0       0       1       0       0</span></span>
<span><span class="co">## TCGA-A2-A0EV-01A-11W-A050-09       0       0       1       0       0</span></span></code></pre></div>
<p>We use notion <code>left[ref&gt;mut]right</code> to mark each component, e.g. <code>C[T&gt;G]A</code> means a base T with 5’ adjacent base C and 3’ adjacent base A is mutated to base G.</p>
</div>
<div id="other-situations" class="section level3" number="3.2.2">
<h3>
<span class="header-section-number">3.2.2</span> Other Situations<a class="anchor" aria-label="anchor" href="#other-situations"><i class="fas fa-link"></i></a>
</h3>
<p>Above we show the most common SBS classifications, there are other situations supported by <strong>sigminer</strong>, including other classifications for SBS records and other mutation types (DBS and ID). All situations about SBS, DBS and ID signatures are well documented in <a href="https://osf.io/s93d5/wiki/home/">wiki of <strong>SigProfilerMatrixGenerator</strong> package</a>.</p>
<div id="other-sbs-classifications" class="section level4" number="3.2.2.1">
<h4>
<span class="header-section-number">3.2.2.1</span> Other SBS classifications<a class="anchor" aria-label="anchor" href="#other-sbs-classifications"><i class="fas fa-link"></i></a>
</h4>
<p>After calling <code><a href="https://rdrr.io/pkg/sigminer/man/sig_tally.html">sig_tally()</a></code>, the most used matrix is stored in <code>nmf_matrix</code>, and all matrices generated by <strong>sigminer</strong> are stored in <code>all_matrices</code>.</p>
<div class="sourceCode" id="cb16"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="fu"><a href="https://rdrr.io/r/utils/str.html">str</a></span><span class="op">(</span><span class="va">mt_tally</span><span class="op">$</span><span class="va">all_matrices</span>, max.level <span class="op">=</span> <span class="fl">1</span><span class="op">)</span></span>
<span><span class="co">## List of 3</span></span>
<span><span class="co">##  $ SBS_6   : int [1:100, 1:6] 7 6 5 4 9 7 5 5 0 5 ...</span></span>
<span><span class="co">##   ..- attr(*, "dimnames")=List of 2</span></span>
<span><span class="co">##  $ SBS_96  : int [1:100, 1:96] 0 0 0 0 0 0 1 2 0 0 ...</span></span>
<span><span class="co">##   ..- attr(*, "dimnames")=List of 2</span></span>
<span><span class="co">##  $ SBS_1536: int [1:100, 1:1536] 0 0 0 0 0 0 0 0 0 0 ...</span></span>
<span><span class="co">##   ..- attr(*, "dimnames")=List of 2</span></span></code></pre></div>
<p>If you add the strand classification, all matrices can be generated by <strong>sigminer</strong> will return.</p>
<div class="sourceCode" id="cb17"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="va">mt_tally2</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/pkg/sigminer/man/sig_tally.html">sig_tally</a></span><span class="op">(</span></span>
<span>  <span class="va">brca</span>,</span>
<span>  ref_genome <span class="op">=</span> <span class="st">"BSgenome.Hsapiens.UCSC.hg19"</span>,</span>
<span>  use_syn <span class="op">=</span> <span class="cn">TRUE</span>, add_trans_bias <span class="op">=</span> <span class="cn">TRUE</span></span>
<span><span class="op">)</span></span>
<span><span class="co">## ℹ [2021-12-04 23:50:10]: Started.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:50:10]: We would assume you marked all variants' position in + strand.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:50:10]: Reference genome loaded.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:50:10]: Variants from MAF object queried.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:50:10]: Chromosome names checked.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:50:10]: Sex chromosomes properly handled.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:50:10]: Only variants located in standard chromosomes (1:22, X, Y, M/MT) are kept.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:50:10]: Variant start and end position checked.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:50:10]: Variant data for matrix generation preprocessed.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:50:10]: SBS matrix generation - start.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:50:10]: Extracting 5' and 3' adjacent bases.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:50:11]: Extracting +/- 20bp around mutated bases for background C&gt;T estimation.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:50:11]: Estimating APOBEC enrichment scores.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:50:11]: Performing one-way Fisher's test for APOBEC enrichment.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:50:11]: APOBEC related mutations are enriched in 28% of samples (APOBEC enrichment score &gt; 2; 28 of 100 samples)</span></span>
<span><span class="co">## ℹ [2021-12-04 23:50:11]: Creating SBS sample-by-component matrices.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:50:11]: SBS-6 matrix created.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:50:11]: SBS-96 matrix created.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:50:11]: SBS-1536 matrix created.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:50:12]: SBS-24 (6x4) matrix created.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:50:12]: SBS-384 (96x4) matrix created.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:50:12]: SBS-6144 (1536x4) matrix created.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:50:12]: Return SBS-192 as major matrix.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:50:12]: Done.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:50:12]: 2.451 secs elapsed.</span></span>
<span><span class="fu"><a href="https://rdrr.io/r/utils/str.html">str</a></span><span class="op">(</span><span class="va">mt_tally2</span><span class="op">$</span><span class="va">all_matrices</span>, max.level <span class="op">=</span> <span class="fl">1</span><span class="op">)</span></span>
<span><span class="co">## List of 7</span></span>
<span><span class="co">##  $ SBS_6   : int [1:100, 1:6] 7 6 5 4 9 7 5 5 0 5 ...</span></span>
<span><span class="co">##   ..- attr(*, "dimnames")=List of 2</span></span>
<span><span class="co">##  $ SBS_24  : int [1:100, 1:24] 6 3 3 2 6 4 1 2 0 3 ...</span></span>
<span><span class="co">##   ..- attr(*, "dimnames")=List of 2</span></span>
<span><span class="co">##  $ SBS_96  : int [1:100, 1:96] 0 0 0 0 0 0 1 2 0 0 ...</span></span>
<span><span class="co">##   ..- attr(*, "dimnames")=List of 2</span></span>
<span><span class="co">##  $ SBS_192 : int [1:100, 1:192] 0 0 0 0 0 0 0 0 0 0 ...</span></span>
<span><span class="co">##   ..- attr(*, "dimnames")=List of 2</span></span>
<span><span class="co">##  $ SBS_384 : int [1:100, 1:384] 0 0 0 0 0 0 0 0 0 0 ...</span></span>
<span><span class="co">##   ..- attr(*, "dimnames")=List of 2</span></span>
<span><span class="co">##  $ SBS_1536: int [1:100, 1:1536] 0 0 0 0 0 0 0 0 0 0 ...</span></span>
<span><span class="co">##   ..- attr(*, "dimnames")=List of 2</span></span>
<span><span class="co">##  $ SBS_6144: int [1:100, 1:6144] 0 0 0 0 0 0 0 0 0 0 ...</span></span>
<span><span class="co">##   ..- attr(*, "dimnames")=List of 2</span></span></code></pre></div>
</div>
<div id="dbs-and-id-components" class="section level4" number="3.2.2.2">
<h4>
<span class="header-section-number">3.2.2.2</span> DBS and ID components<a class="anchor" aria-label="anchor" href="#dbs-and-id-components"><i class="fas fa-link"></i></a>
</h4>
<p>If you want to generate DBS or ID matrices, just modify the <code>mode</code> option.</p>
<div class="sourceCode" id="cb18"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="va">mt_tally_DBS</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/pkg/sigminer/man/sig_tally.html">sig_tally</a></span><span class="op">(</span></span>
<span>  <span class="va">brca</span>,</span>
<span>  ref_genome <span class="op">=</span> <span class="st">"BSgenome.Hsapiens.UCSC.hg19"</span>,</span>
<span>  use_syn <span class="op">=</span> <span class="cn">TRUE</span>,</span>
<span>  mode <span class="op">=</span> <span class="st">"DBS"</span>,</span>
<span>  add_trans_bias <span class="op">=</span> <span class="cn">TRUE</span></span>
<span><span class="op">)</span></span>
<span><span class="co">## ℹ [2021-12-04 23:50:13]: Started.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:50:13]: We would assume you marked all variants' position in + strand.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:50:13]: Reference genome loaded.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:50:13]: Variants from MAF object queried.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:50:13]: Chromosome names checked.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:50:13]: Sex chromosomes properly handled.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:50:13]: Only variants located in standard chromosomes (1:22, X, Y, M/MT) are kept.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:50:13]: Variant start and end position checked.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:50:13]: Variant data for matrix generation preprocessed.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:50:13]: DBS matrix generation - start.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:50:13]: Searching DBS records...</span></span>
<span><span class="co">## ✓ [2021-12-04 23:50:13]: Done.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:50:15]: Reference sequences queried from genome.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:50:15]: DBS-78 matrix created.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:50:15]: DBS-1248 matrix created.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:50:15]: DBS-186 matrix created.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:50:15]: Return DBS-186 as major matrix.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:50:15]: Done.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:50:15]: 2.172 secs elapsed.</span></span>
<span><span class="fu"><a href="https://rdrr.io/r/utils/str.html">str</a></span><span class="op">(</span><span class="va">mt_tally_DBS</span><span class="op">$</span><span class="va">all_matrices</span>, max.level <span class="op">=</span> <span class="fl">1</span><span class="op">)</span></span>
<span><span class="co">## List of 3</span></span>
<span><span class="co">##  $ DBS_78  : int [1:100, 1:78] 0 0 0 0 0 0 0 0 0 0 ...</span></span>
<span><span class="co">##   ..- attr(*, "dimnames")=List of 2</span></span>
<span><span class="co">##  $ DBS_186 : int [1:100, 1:186] 0 0 0 0 0 0 0 0 0 0 ...</span></span>
<span><span class="co">##   ..- attr(*, "dimnames")=List of 2</span></span>
<span><span class="co">##  $ DBS_1248: int [1:100, 1:1248] 0 0 0 0 0 0 0 0 0 0 ...</span></span>
<span><span class="co">##   ..- attr(*, "dimnames")=List of 2</span></span></code></pre></div>
<blockquote>
<p>Program will stop if no records to analyze.
Let’s see ID records.</p>
</blockquote>
<div class="sourceCode" id="cb19"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="va">mt_tally_ID</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/pkg/sigminer/man/sig_tally.html">sig_tally</a></span><span class="op">(</span></span>
<span>  <span class="va">brca</span>,</span>
<span>  ref_genome <span class="op">=</span> <span class="st">"BSgenome.Hsapiens.UCSC.hg19"</span>,</span>
<span>  use_syn <span class="op">=</span> <span class="cn">TRUE</span>,</span>
<span>  mode <span class="op">=</span> <span class="st">"ID"</span>,</span>
<span>  add_trans_bias <span class="op">=</span> <span class="cn">TRUE</span></span>
<span><span class="op">)</span></span>
<span><span class="co">## ℹ [2021-12-04 23:50:15]: Started.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:50:15]: We would assume you marked all variants' position in + strand.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:50:15]: Reference genome loaded.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:50:15]: Variants from MAF object queried.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:50:15]: Chromosome names checked.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:50:15]: Sex chromosomes properly handled.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:50:15]: Only variants located in standard chromosomes (1:22, X, Y, M/MT) are kept.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:50:15]: Variant start and end position checked.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:50:15]: Variant data for matrix generation preprocessed.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:50:15]: INDEL matrix generation - start.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:50:17]: Reference sequences queried from genome.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:50:17]: INDEL length extracted.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:50:17]: Adjacent copies counted.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:50:40]: Microhomology size calculated.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:50:40]: INDEL records classified into different components (types).</span></span>
<span><span class="co">## ✓ [2021-12-04 23:50:40]: ID-28 matrix created.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:50:40]: ID-83 matrix created.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:50:40]: ID-415 matrix created.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:50:40]: Return ID-415 as major matrix.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:50:40]: Done.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:50:40]: 24.857 secs elapsed.</span></span>
<span><span class="fu"><a href="https://rdrr.io/r/utils/str.html">str</a></span><span class="op">(</span><span class="va">mt_tally_ID</span><span class="op">$</span><span class="va">all_matrices</span>, max.level <span class="op">=</span> <span class="fl">1</span><span class="op">)</span></span>
<span><span class="co">## List of 3</span></span>
<span><span class="co">##  $ ID_28 : int [1:100, 1:28] 0 1 0 0 0 0 0 0 0 0 ...</span></span>
<span><span class="co">##   ..- attr(*, "dimnames")=List of 2</span></span>
<span><span class="co">##  $ ID_83 : int [1:100, 1:83] 0 1 0 0 0 0 0 0 0 0 ...</span></span>
<span><span class="co">##   ..- attr(*, "dimnames")=List of 2</span></span>
<span><span class="co">##  $ ID_415:'data.frame':  100 obs. of  415 variables:</span></span></code></pre></div>
</div>
<div id="take-togother" class="section level4" number="3.2.2.3">
<h4>
<span class="header-section-number">3.2.2.3</span> Take togother<a class="anchor" aria-label="anchor" href="#take-togother"><i class="fas fa-link"></i></a>
</h4>
<p>If you want to get all matrices for SBS, DBS and ID at the same time, you don’t need to write a <code>for</code> loop or type three times to do this.
Just set <code>mode='ALL'</code>, <strong>sigminer</strong> will do it for you!</p>
<div class="sourceCode" id="cb20"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="va">mt_tally_all</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/pkg/sigminer/man/sig_tally.html">sig_tally</a></span><span class="op">(</span></span>
<span>  <span class="va">brca</span>,</span>
<span>  ref_genome <span class="op">=</span> <span class="st">"BSgenome.Hsapiens.UCSC.hg19"</span>,</span>
<span>  use_syn <span class="op">=</span> <span class="cn">TRUE</span>,</span>
<span>  mode <span class="op">=</span> <span class="st">"ALL"</span>,</span>
<span>  add_trans_bias <span class="op">=</span> <span class="cn">TRUE</span></span>
<span><span class="op">)</span></span>
<span><span class="co">## ℹ [2021-12-04 23:50:40]: Started.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:50:40]: We would assume you marked all variants' position in + strand.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:50:40]: Reference genome loaded.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:50:40]: Variants from MAF object queried.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:50:40]: Chromosome names checked.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:50:40]: Sex chromosomes properly handled.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:50:40]: Only variants located in standard chromosomes (1:22, X, Y, M/MT) are kept.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:50:40]: Variant start and end position checked.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:50:40]: Variant data for matrix generation preprocessed.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:50:40]: All types of matrices generation - start.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:50:40]: SBS matrix generation - start.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:50:40]: Extracting 5' and 3' adjacent bases.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:50:42]: Extracting +/- 20bp around mutated bases for background C&gt;T estimation.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:50:43]: Estimating APOBEC enrichment scores.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:50:43]: Performing one-way Fisher's test for APOBEC enrichment.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:50:43]: APOBEC related mutations are enriched in 28% of samples (APOBEC enrichment score &gt; 2; 28 of 100 samples)</span></span>
<span><span class="co">## ℹ [2021-12-04 23:50:43]: Creating SBS sample-by-component matrices.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:50:43]: SBS-6 matrix created.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:50:43]: SBS-96 matrix created.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:50:43]: SBS-1536 matrix created.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:50:43]: SBS-24 (6x4) matrix created.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:50:43]: SBS-384 (96x4) matrix created.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:50:43]: SBS-6144 (1536x4) matrix created.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:50:43]: Return SBS-192 as major matrix.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:50:43]: DBS matrix generation - start.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:50:43]: Searching DBS records...</span></span>
<span><span class="co">## ✓ [2021-12-04 23:50:44]: Done.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:50:45]: Reference sequences queried from genome.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:50:45]: DBS-78 matrix created.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:50:45]: DBS-1248 matrix created.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:50:46]: DBS-186 matrix created.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:50:46]: Return DBS-186 as major matrix.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:50:46]: INDEL matrix generation - start.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:50:48]: Reference sequences queried from genome.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:50:48]: INDEL length extracted.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:50:48]: Adjacent copies counted.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:51:11]: Microhomology size calculated.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:51:12]: INDEL records classified into different components (types).</span></span>
<span><span class="co">## ✓ [2021-12-04 23:51:12]: ID-28 matrix created.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:51:12]: ID-83 matrix created.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:51:12]: ID-415 matrix created.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:12]: Return ID-415 as major matrix.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:12]: All types of matrices generation (APOBEC scores included) - end.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:51:12]: Done.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:12]: 31.747 secs elapsed.</span></span>
<span><span class="fu"><a href="https://rdrr.io/r/utils/str.html">str</a></span><span class="op">(</span><span class="va">mt_tally_all</span>, max.level <span class="op">=</span> <span class="fl">1</span><span class="op">)</span></span>
<span><span class="co">## List of 14</span></span>
<span><span class="co">##  $ SBS_6        : int [1:100, 1:6] 7 6 5 4 9 7 5 5 0 5 ...</span></span>
<span><span class="co">##   ..- attr(*, "dimnames")=List of 2</span></span>
<span><span class="co">##  $ SBS_24       : int [1:100, 1:24] 6 3 3 2 6 4 1 2 0 3 ...</span></span>
<span><span class="co">##   ..- attr(*, "dimnames")=List of 2</span></span>
<span><span class="co">##  $ SBS_96       : int [1:100, 1:96] 0 0 0 0 0 0 1 2 0 0 ...</span></span>
<span><span class="co">##   ..- attr(*, "dimnames")=List of 2</span></span>
<span><span class="co">##  $ SBS_192      : int [1:100, 1:192] 0 0 0 0 0 0 0 0 0 0 ...</span></span>
<span><span class="co">##   ..- attr(*, "dimnames")=List of 2</span></span>
<span><span class="co">##  $ SBS_384      : int [1:100, 1:384] 0 0 0 0 0 0 0 0 0 0 ...</span></span>
<span><span class="co">##   ..- attr(*, "dimnames")=List of 2</span></span>
<span><span class="co">##  $ SBS_1536     : int [1:100, 1:1536] 0 0 0 0 0 0 0 0 0 0 ...</span></span>
<span><span class="co">##   ..- attr(*, "dimnames")=List of 2</span></span>
<span><span class="co">##  $ SBS_6144     : int [1:100, 1:6144] 0 0 0 0 0 0 0 0 0 0 ...</span></span>
<span><span class="co">##   ..- attr(*, "dimnames")=List of 2</span></span>
<span><span class="co">##  $ DBS_78       : int [1:100, 1:78] 0 0 0 0 0 0 0 0 0 0 ...</span></span>
<span><span class="co">##   ..- attr(*, "dimnames")=List of 2</span></span>
<span><span class="co">##  $ DBS_186      : int [1:100, 1:186] 0 0 0 0 0 0 0 0 0 0 ...</span></span>
<span><span class="co">##   ..- attr(*, "dimnames")=List of 2</span></span>
<span><span class="co">##  $ DBS_1248     : int [1:100, 1:1248] 0 0 0 0 0 0 0 0 0 0 ...</span></span>
<span><span class="co">##   ..- attr(*, "dimnames")=List of 2</span></span>
<span><span class="co">##  $ ID_28        : int [1:100, 1:28] 0 1 0 0 0 0 0 0 0 0 ...</span></span>
<span><span class="co">##   ..- attr(*, "dimnames")=List of 2</span></span>
<span><span class="co">##  $ ID_83        : int [1:100, 1:83] 0 1 0 0 0 0 0 0 0 0 ...</span></span>
<span><span class="co">##   ..- attr(*, "dimnames")=List of 2</span></span>
<span><span class="co">##  $ ID_415       :'data.frame':   100 obs. of  415 variables:</span></span>
<span><span class="co">##  $ APOBEC_scores:Classes 'data.table' and 'data.frame':  100 obs. of  44 variables:</span></span>
<span><span class="co">##   ..- attr(*, ".internal.selfref")=&lt;externalptr&gt; </span></span>
<span><span class="co">##   ..- attr(*, "index")= int(0) </span></span>
<span><span class="co">##   .. ..- attr(*, "__APOBEC_Enriched")= int [1:100] 17 21 23 24 25 26 27 28 30 32 ...</span></span></code></pre></div>
<p>Please note, in this case, just a list containing matrices will return.</p>
</div>
</div>
</div>
<div id="de-novo-signature-discovery" class="section level2" number="3.3">
<h2>
<span class="header-section-number">3.3</span> <em>de novo</em> signature discovery<a class="anchor" aria-label="anchor" href="#de-novo-signature-discovery"><i class="fas fa-link"></i></a>
</h2>
<p><strong>Sigminer</strong> provides many approaches to extract mutational signatures. To test their performances, We use 4 mutation catalog datasets (each mutation catalog dataset is composed of 30 samples, 10 COSMIC v2 (SBS) signatures are randomly assigned to each sample with random signature exposure/activity) from <span class="citation">Degasperi et al. (<a href="references.html#ref-degasperi2020practical" role="doc-biblioref">2020</a>)</span>. The following table shows how many signatures can be recovered and the corresponding average cosine similarity to COSMIC reference signatures for each approach with settings.</p>
<div class="inline-table"><table class="table table-sm">
<colgroup>
<col width="3%">
<col width="5%">
<col width="13%">
<col width="7%">
<col width="2%">
<col width="4%">
<col width="2%">
<col width="2%">
<col width="4%">
<col width="2%">
<col width="3%">
<col width="4%">
<col width="40%">
</colgroup>
<thead><tr class="header">
<th align="left">Approach</th>
<th align="left">Selection Way</th>
<th align="left">Setting</th>
<th align="left">Caller</th>
<th align="left">Recommend</th>
<th align="left">Driver</th>
<th align="left">Set1</th>
<th align="left">Set2</th>
<th align="left">Set3</th>
<th align="left">Set4</th>
<th align="left">Success /Mean</th>
<th align="left">Run time</th>
<th>Note</th>
</tr></thead>
<tbody>
<tr class="odd">
<td align="left">Standard NMF</td>
<td align="left">Manual</td>
<td align="left">Default. 50 runs (estimation) + 100 runs (extraction)</td>
<td align="left">
<code>sig_estimate</code>, <code>sig_extract</code>
</td>
<td align="left">YES ⭐⭐⭐</td>
<td align="left">R</td>
<td align="left">10 (0.884)</td>
<td align="left">10 (0.944)</td>
<td align="left">9 or 10 (0.998)</td>
<td align="left">10 (0.994)</td>
<td align="left">~90%/0.955</td>
<td align="left">~1min (8 cores)</td>
<td>This is a basic method, suitable for good mutation data with enough mutations.</td>
</tr>
<tr class="even">
<td align="left">SigProfiler</td>
<td align="left"><strong>Manual/Automatic</strong></td>
<td align="left">Default. 100 runs</td>
<td align="left"><code>sigprofiler_extract</code></td>
<td align="left">YES ⭐⭐⭐⭐</td>
<td align="left">Python/Anaconda</td>
<td align="left">10 (0.961)</td>
<td align="left">10 (0.999)</td>
<td align="left">10 (0.990)</td>
<td align="left">10 (0.997)</td>
<td align="left">100%/0.987</td>
<td align="left">~1h (8 cores)</td>
<td>A golden standard like approach in this field, but longer run time, and the requirement for Python environment and extra large packages reduce its popularity here.</td>
</tr>
<tr class="odd">
<td align="left">Best Practice</td>
<td align="left"><strong>Manual/Automatic</strong></td>
<td align="left">Use bootstrapped catalog (1000 runs)</td>
<td align="left"><code>bp_extract_signatures</code></td>
<td align="left">YES ⭐⭐⭐⭐⭐</td>
<td align="left">R</td>
<td align="left">10 (0.973)</td>
<td align="left">10 (0.990)</td>
<td align="left">10 (0.992)</td>
<td align="left">10 (0.971)</td>
<td align="left">100%/0.981</td>
<td align="left">~10min (8 cores)</td>
<td>My R implementation for methods from reference #5 and #6. Should be the best option here. (<strong>Pay attention to the suggested solution</strong>)</td>
</tr>
<tr class="even">
<td align="left">Best Practice</td>
<td align="left"><strong>Manual/Automatic</strong></td>
<td align="left">Use original catalog (1000 runs)</td>
<td align="left"><code>bp_extract_signatures</code></td>
<td align="left">NO :star:</td>
<td align="left">R</td>
<td align="left">10 (0.987)</td>
<td align="left">9 (0.985)</td>
<td align="left">10 (0.997)</td>
<td align="left">9 (0.987)</td>
<td align="left">50%/0.989</td>
<td align="left">~10min (8 cores)</td>
<td>This is created to compare with the approach with bootstrapped catalogs above and the standard NMF way.</td>
</tr>
<tr class="odd">
<td align="left">Bayesian NMF</td>
<td align="left"><strong>Automatic</strong></td>
<td align="left">L1KL+optimal (20 runs)</td>
<td align="left"><code>sig_auto_extract</code></td>
<td align="left">YES ⭐⭐⭐</td>
<td align="left">R</td>
<td align="left">10 (0.994)</td>
<td align="left">9 (0.997)</td>
<td align="left">9 (0.998)</td>
<td align="left">9 (0.999)</td>
<td align="left">25%/0.997</td>
<td align="left">~10min (8 cores)</td>
<td>The Bayesian NMF approach auto reduce the signature number to a proper value from a initial signature number, here is 20.</td>
</tr>
<tr class="even">
<td align="left">Bayesian NMF</td>
<td align="left"><strong>Automatic</strong></td>
<td align="left">L1KL+stable (20 runs)</td>
<td align="left"><code>sig_auto_extract</code></td>
<td align="left">YES ⭐⭐⭐⭐</td>
<td align="left">R</td>
<td align="left">10 (0.994)</td>
<td align="left">9 (0.997)</td>
<td align="left">10 (0.988)</td>
<td align="left">9 (0.999)</td>
<td align="left">50%/0.995</td>
<td align="left">~10min (8 cores)</td>
<td>See above.</td>
</tr>
<tr class="odd">
<td align="left">Bayesian NMF</td>
<td align="left"><strong>Automatic</strong></td>
<td align="left">L2KL+optimal (20 runs)</td>
<td align="left"><code>sig_auto_extract</code></td>
<td align="left">NO :star:</td>
<td align="left">R</td>
<td align="left">12 (0.990)</td>
<td align="left">13 (0.988)</td>
<td align="left">12 (0.902)</td>
<td align="left">12 (0.994)</td>
<td align="left">0%/0.969</td>
<td align="left">~10min (8 cores)</td>
<td>See above.</td>
</tr>
<tr class="even">
<td align="left">Bayesian NMF</td>
<td align="left"><strong>Automatic</strong></td>
<td align="left">L2KL+stable (20 runs)</td>
<td align="left"><code>sig_auto_extract</code></td>
<td align="left">NO :star:</td>
<td align="left">R</td>
<td align="left">12 (0.990)</td>
<td align="left">12 (0.988)</td>
<td align="left">12 (0.902)</td>
<td align="left">12 (0.994)</td>
<td align="left">0%/0.969</td>
<td align="left">~10min (8 cores)</td>
<td>See above.</td>
</tr>
<tr class="odd">
<td align="left">Bayesian NMF</td>
<td align="left"><strong>Automatic</strong></td>
<td align="left">L1WL2H+optimal (20 runs)</td>
<td align="left"><code>sig_auto_extract</code></td>
<td align="left">YES ⭐⭐⭐</td>
<td align="left">R</td>
<td align="left">9 (0.989)</td>
<td align="left">9 (0.999)</td>
<td align="left">9 (0.996)</td>
<td align="left">9 (1.000)</td>
<td align="left">0%/0.996</td>
<td align="left">~10min (8 cores)</td>
<td>See above.</td>
</tr>
<tr class="even">
<td align="left">Bayesian NMF</td>
<td align="left"><strong>Automatic</strong></td>
<td align="left">L1WL2H+stable (20 runs)</td>
<td align="left"><code>sig_auto_extract</code></td>
<td align="left">YES ⭐⭐⭐⭐</td>
<td align="left">R</td>
<td align="left">9 (0.989)</td>
<td align="left">9 (0.999)</td>
<td align="left">9 (0.996)</td>
<td align="left">9 (1.000)</td>
<td align="left">0%/0.996</td>
<td align="left">~10min (8 cores)</td>
<td>See above.</td>
</tr>
</tbody>
</table></div>
<blockquote>
<p>NOTE: although Bayesian NMF approach with L1KL or L1WL2H prior cannot recover all 10 signatures here, but it is close to the true answer from initial signature number 20 in a automatic way, and the result signatures are highly similar to reference signatures. This also reminds us that we could not use this method to find signatures with small contributions in tumors.</p>
</blockquote>
<p>From <strong>sigminer</strong> v2.1.0, an unified interface <code><a href="https://rdrr.io/pkg/sigminer/man/sig_unify_extract.html">sig_unify_extract()</a></code>. has been implemented to access the
4 signature extraction approaches.</p>
<div class="sourceCode" id="cb21"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="fu"><a href="https://rdrr.io/r/base/args.html">args</a></span><span class="op">(</span><span class="va">sig_unify_extract</span><span class="op">)</span></span>
<span><span class="co">## function (nmf_matrix, range = 2:5, nrun = 10, approach = c("bayes_nmf", </span></span>
<span><span class="co">##     "repeated_nmf", "bootstrap_nmf", "sigprofiler"), cores = 1L, </span></span>
<span><span class="co">##     ...) </span></span>
<span><span class="co">## NULL</span></span></code></pre></div>
<p>Once you determine a method, please read all parameters shown in the detail function.</p>
<ul>
<li>“bayes_nmf” corresponds to <code><a href="https://rdrr.io/pkg/sigminer/man/sig_auto_extract.html">sig_auto_extract()</a></code>.</li>
<li>“repeated_nmf” corresponds to <code><a href="https://rdrr.io/pkg/sigminer/man/sig_extract.html">sig_extract()</a></code>.</li>
<li>“bootstrap_nmf” coresponds to <code><a href="https://rdrr.io/pkg/sigminer/man/bp.html">bp_extract_signatures()</a></code>.</li>
<li>“sigprofiler” corresponds to <code><a href="https://rdrr.io/pkg/sigminer/man/sigprofiler.html">sigprofiler_extract()</a></code>.</li>
</ul>
<p>Note, when you use <code><a href="https://rdrr.io/pkg/sigminer/man/sig_extract.html">sig_extract()</a></code> (“repeated_nmf”) and you don’t know how
to select the signature number, you should run <code><a href="https://rdrr.io/pkg/sigminer/man/sig_estimate.html">sig_estimate()</a></code> firstly.</p>
<div id="manual-signature-estimation-and-extraction" class="section level3" number="3.3.1">
<h3>
<span class="header-section-number">3.3.1</span> Manual signature estimation and extraction<a class="anchor" aria-label="anchor" href="#manual-signature-estimation-and-extraction"><i class="fas fa-link"></i></a>
</h3>
<p>For example, let’s try signature number 2-6. For simplicity, we just run NMF 10 times for each signature number. We use 4 cores to speed up the computation.</p>
<div class="sourceCode" id="cb22"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="va">mt_est</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/pkg/sigminer/man/sig_estimate.html">sig_estimate</a></span><span class="op">(</span><span class="va">mt_tally</span><span class="op">$</span><span class="va">nmf_matrix</span>,</span>
<span>  range <span class="op">=</span> <span class="fl">2</span><span class="op">:</span><span class="fl">6</span>,</span>
<span>  nrun <span class="op">=</span> <span class="fl">10</span>, <span class="co"># increase this value if you wana a more stable estimation</span></span>
<span>  use_random <span class="op">=</span> <span class="cn">FALSE</span>, <span class="co"># if TRUE, add results from randomized input</span></span>
<span>  cores <span class="op">=</span> <span class="fl">4</span>,</span>
<span>  verbose <span class="op">=</span> <span class="cn">TRUE</span></span>
<span><span class="op">)</span></span></code></pre></div>
<p>We can show signature number survey for different measures by <code><a href="https://rdrr.io/pkg/sigminer/man/sig_estimate.html">show_sig_number_survey2()</a></code>.</p>
<div class="sourceCode" id="cb23"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co">## You can also select the measures to show</span></span>
<span><span class="co">## by 'what' option</span></span>
<span><span class="fu"><a href="https://rdrr.io/pkg/sigminer/man/sig_estimate.html">show_sig_number_survey2</a></span><span class="op">(</span><span class="va">mt_est</span><span class="op">$</span><span class="va">survey</span><span class="op">)</span></span></code></pre></div>
<div class="inline-figure"><img src="sigminer_files/figure-html/unnamed-chunk-33-1.png" width="95%"></div>
<blockquote>
<p>For the details of all the measures above, please read <span class="citation">Gaujoux and Seoighe (<a href="references.html#ref-gaujoux2010flexible" role="doc-biblioref">2010</a>)</span> and <a href="https://cran.r-project.org/web/packages/NMF/vignettes/">vignette</a> of R package <strong>NMF</strong>.
The measures either provide stability (<code>cophenetic</code>) or how well can be reconstructed (<code>rss</code>).</p>
</blockquote>
<p>Typically, measure <strong>cophenetic</strong> is used for determining the signature number. We can easily generate an elbow plot
with function <code><a href="https://rdrr.io/pkg/sigminer/man/sig_estimate.html">show_sig_number_survey()</a></code>.</p>
<div class="sourceCode" id="cb24"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="fu"><a href="https://rdrr.io/pkg/sigminer/man/sig_estimate.html">show_sig_number_survey</a></span><span class="op">(</span><span class="va">mt_est</span><span class="op">$</span><span class="va">survey</span>, right_y <span class="op">=</span> <span class="cn">NULL</span><span class="op">)</span></span></code></pre></div>
<div class="inline-figure"><img src="sigminer_files/figure-html/unnamed-chunk-34-1.png" width="95%"></div>
<blockquote>
<p>The most common approach is to use the cophenetic correlation coefficient. Brunet et al. suggested choosing the smallest value of r for which this coefficient starts decreasing. <span class="citation">(<a href="references.html#ref-gaujoux2010flexible" role="doc-biblioref">Gaujoux and Seoighe 2010</a>)</span>
Cophenetic value (range from 0-1) indicates the robustness of consensus matrix clustering. In this situation, 3 is good. However, we can found that the cophenetic values are all &gt;=0.9 from 2 to 5. So the more suitable way is considering both stability and reconstruction error at the same time, it can be easily done by <code><a href="https://rdrr.io/pkg/sigminer/man/sig_estimate.html">show_sig_number_survey()</a></code>.</p>
</blockquote>
<div class="sourceCode" id="cb25"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="fu"><a href="https://rdrr.io/pkg/sigminer/man/sig_estimate.html">show_sig_number_survey</a></span><span class="op">(</span><span class="va">mt_est</span><span class="op">$</span><span class="va">survey</span><span class="op">)</span></span></code></pre></div>
<div class="inline-figure"><img src="sigminer_files/figure-html/unnamed-chunk-35-1.png" width="95%"></div>
<blockquote>
<p>This function is very flexible, you can pick up any measure to the left/right axis. However, the default setting is the most recommended way.
We can see that we get a minimal RSS in signature number, and when this value goes from 5 to 6, the RSS increase! So we should not choose signature number more than 5 here because 6 is overfitting.</p>
</blockquote>
<p><strong>NOTE</strong>: There are no gold standard to determine the signature number. Sometimes, you should consider multiple measures. Remember, the most important thing is that <strong>you should have a good biological explanation for each signature</strong>.
The best solution in study may not be the best solution in math.</p>
<p>Now that the 5 signatures should be a stable solution, next we can extract it with
more runs to obtain the optimal result. In general, use 30~50 NMF runs will get a robust result.</p>
<div class="sourceCode" id="cb26"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="va">mt_sig</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/pkg/sigminer/man/sig_extract.html">sig_extract</a></span><span class="op">(</span><span class="va">mt_tally</span><span class="op">$</span><span class="va">nmf_matrix</span>,</span>
<span>  n_sig <span class="op">=</span> <span class="fl">5</span>,</span>
<span>  nrun <span class="op">=</span> <span class="fl">30</span>,</span>
<span>  cores <span class="op">=</span> <span class="fl">4</span></span>
<span><span class="op">)</span></span></code></pre></div>
</div>
<div id="automatic-extraction" class="section level3" number="3.3.2">
<h3>
<span class="header-section-number">3.3.2</span> Automatic extraction<a class="anchor" aria-label="anchor" href="#automatic-extraction"><i class="fas fa-link"></i></a>
</h3>
<p>If you have no idea to select an optimal signature number from procedures above, you can try auto-extraction approaches provided by <strong>sigminer</strong>.</p>
<p>The latest version of <strong>sigminer</strong> provides three ways to auto-extract mutational signatures.</p>
<ol style="list-style-type: decimal">
<li>Auto-extract signatures by automatic relevance determination technique in non-negative matrix factorization <span class="citation">(<a href="references.html#ref-tan2012automatic" role="doc-biblioref">Tan and Févotte 2012</a>)</span>, the code is implemented by <strong>SignatureAnalyzer</strong> <span class="citation">(<a href="references.html#ref-kim2016somatic" role="doc-biblioref">Kim et al. 2016</a>)</span> and exported to <strong>sigminer</strong>. This approach is known as bayesian NMF and the default approach in <code><a href="https://rdrr.io/pkg/sigminer/man/sig_unify_extract.html">sig_unify_extract()</a></code>.</li>
<li>Auto-extract signatures by <a href="https://github.com/AlexandrovLab/SigProfilerExtractor">SigProfiler</a>, the gold-standard tool used for identifying signatures cataloged in COSMIC database. The technical details please read <span class="citation">Alexandrov et al. (<a href="references.html#ref-alexandrov2020repertoire" role="doc-biblioref">2020</a>)</span>.</li>
<li>Multiple NMF runs with bootstrapped mutation catalogs. This method is adopted from <span class="citation">Degasperi et al. (<a href="references.html#ref-degasperi2020practical" role="doc-biblioref">2020</a>)</span>.</li>
</ol>
<div id="method-1-bayesian-nmf" class="section level4" number="3.3.2.1">
<h4>
<span class="header-section-number">3.3.2.1</span> Method 1: Bayesian NMF<a class="anchor" aria-label="anchor" href="#method-1-bayesian-nmf"><i class="fas fa-link"></i></a>
</h4>
<p>In this approach, you need to set a maximum signature number (default is <code>25</code>) and run times to get the result. 10 for <code>nrun</code> here is okay, and more than 100 is not recommended.
The Bayesian NMF will starts from a larger signature number and reduce it to a proper signature number to maximize posterior probability.</p>
<div class="sourceCode" id="cb27"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="va">mt_sig2</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/pkg/sigminer/man/sig_unify_extract.html">sig_unify_extract</a></span><span class="op">(</span><span class="va">mt_tally</span><span class="op">$</span><span class="va">nmf_matrix</span>, range <span class="op">=</span> <span class="fl">10</span>, nrun <span class="op">=</span> <span class="fl">10</span><span class="op">)</span></span></code></pre></div>
<p>This is same as:</p>
<div class="sourceCode" id="cb28"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="va">mt_sig2</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/pkg/sigminer/man/sig_auto_extract.html">sig_auto_extract</a></span><span class="op">(</span><span class="va">mt_tally</span><span class="op">$</span><span class="va">nmf_matrix</span>,</span>
<span>  K0 <span class="op">=</span> <span class="fl">10</span>, nrun <span class="op">=</span> <span class="fl">10</span>,</span>
<span>  strategy <span class="op">=</span> <span class="st">"stable"</span></span>
<span><span class="op">)</span></span></code></pre></div>
<p>Here the program uses <strong>‘robust’ strategy</strong> to return the result (see <code>strategy</code> option). It means that if you run 10 times and 6 of them return <code>4</code> signatures, then the optimal result with <code>4</code> signatures will be returned.</p>
<p>The info of each run can be given as:</p>
<div class="sourceCode" id="cb29"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="fu">knitr</span><span class="fu">::</span><span class="fu"><a href="https://rdrr.io/pkg/knitr/man/kable.html">kable</a></span><span class="op">(</span><span class="va">mt_sig2</span><span class="op">$</span><span class="va">Raw</span><span class="op">$</span><span class="va">summary_run</span><span class="op">)</span></span></code></pre></div>
<div class="inline-table"><table class="table table-sm">
<colgroup>
<col width="4%">
<col width="3%">
<col width="10%">
<col width="81%">
</colgroup>
<thead><tr class="header">
<th align="right">Run</th>
<th align="right">K</th>
<th align="right">posterior</th>
<th align="left">file</th>
</tr></thead>
<tbody>
<tr class="odd">
<td align="right">5</td>
<td align="right">3</td>
<td align="right">-1497.498</td>
<td align="left">/var/folders/qx/5tqxhrrd5xd_n9rfbb_m5c200000gn/T//RtmpPz6VVL/BayesNMF.5.rds</td>
</tr>
<tr class="even">
<td align="right">3</td>
<td align="right">3</td>
<td align="right">-1497.752</td>
<td align="left">/var/folders/qx/5tqxhrrd5xd_n9rfbb_m5c200000gn/T//RtmpPz6VVL/BayesNMF.3.rds</td>
</tr>
<tr class="odd">
<td align="right">7</td>
<td align="right">3</td>
<td align="right">-1497.841</td>
<td align="left">/var/folders/qx/5tqxhrrd5xd_n9rfbb_m5c200000gn/T//RtmpPz6VVL/BayesNMF.7.rds</td>
</tr>
<tr class="even">
<td align="right">1</td>
<td align="right">3</td>
<td align="right">-1498.525</td>
<td align="left">/var/folders/qx/5tqxhrrd5xd_n9rfbb_m5c200000gn/T//RtmpPz6VVL/BayesNMF.1.rds</td>
</tr>
<tr class="odd">
<td align="right">9</td>
<td align="right">3</td>
<td align="right">-1498.528</td>
<td align="left">/var/folders/qx/5tqxhrrd5xd_n9rfbb_m5c200000gn/T//RtmpPz6VVL/BayesNMF.9.rds</td>
</tr>
<tr class="even">
<td align="right">10</td>
<td align="right">3</td>
<td align="right">-1498.883</td>
<td align="left">/var/folders/qx/5tqxhrrd5xd_n9rfbb_m5c200000gn/T//RtmpPz6VVL/BayesNMF.10.rds</td>
</tr>
<tr class="odd">
<td align="right">6</td>
<td align="right">3</td>
<td align="right">-1499.748</td>
<td align="left">/var/folders/qx/5tqxhrrd5xd_n9rfbb_m5c200000gn/T//RtmpPz6VVL/BayesNMF.6.rds</td>
</tr>
<tr class="even">
<td align="right">4</td>
<td align="right">3</td>
<td align="right">-1499.814</td>
<td align="left">/var/folders/qx/5tqxhrrd5xd_n9rfbb_m5c200000gn/T//RtmpPz6VVL/BayesNMF.4.rds</td>
</tr>
<tr class="odd">
<td align="right">8</td>
<td align="right">3</td>
<td align="right">-1500.195</td>
<td align="left">/var/folders/qx/5tqxhrrd5xd_n9rfbb_m5c200000gn/T//RtmpPz6VVL/BayesNMF.8.rds</td>
</tr>
<tr class="even">
<td align="right">2</td>
<td align="right">4</td>
<td align="right">-1604.000</td>
<td align="left">/var/folders/qx/5tqxhrrd5xd_n9rfbb_m5c200000gn/T//RtmpPz6VVL/BayesNMF.2.rds</td>
</tr>
</tbody>
</table></div>
<p>The <code>mt_sig2</code> has similar structure as <code>mut_sig</code>.</p>
</div>
<div id="method-2-sigprofiler" class="section level4" number="3.3.2.2">
<h4>
<span class="header-section-number">3.3.2.2</span> Method 2: SigProfiler<a class="anchor" aria-label="anchor" href="#method-2-sigprofiler"><i class="fas fa-link"></i></a>
</h4>
<p><strong>Sigminer</strong> provides two functions <code><a href="https://rdrr.io/pkg/sigminer/man/sigprofiler.html">sigprofiler_extract()</a></code> and <code><a href="https://rdrr.io/pkg/sigminer/man/sigprofiler.html">sigprofiler_import()</a></code> to install, use SigProfiler and import <a href="https://github.com/AlexandrovLab/SigProfilerExtractor"><strong>SigProfilerExtractor</strong></a> results into R as a <code>Signature</code> object like other extraction methods mentioned above.</p>
<p>An (not running) example is given below (see <code><a href="https://rdrr.io/pkg/sigminer/man/sigprofiler.html">?sigprofiler</a></code> for more info).</p>
<div class="sourceCode" id="cb30"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="fu">reticulate</span><span class="fu">::</span><span class="fu"><a href="https://rstudio.github.io/reticulate/reference/conda-tools.html">conda_list</a></span><span class="op">(</span><span class="op">)</span></span>
<span><span class="fu"><a href="https://rdrr.io/pkg/sigminer/man/sigprofiler.html">sigprofiler_extract</a></span><span class="op">(</span><span class="va">cn_tally_W</span><span class="op">$</span><span class="va">nmf_matrix</span>, <span class="st">"~/test/test_sigminer"</span>,</span>
<span>  use_conda <span class="op">=</span> <span class="cn">TRUE</span></span>
<span><span class="op">)</span></span>
<span></span>
<span><span class="co"># Same as</span></span>
<span><span class="co"># sig_unify_extract(mt_tally$nmf_matrix, use_conda = FALSE, py_path = "/Users/wsx/anaconda3/bin/python", approach = "sigprofiler", out = "~/test/test_sigminer")</span></span>
<span><span class="fu"><a href="https://rdrr.io/pkg/sigminer/man/sigprofiler.html">sigprofiler_extract</a></span><span class="op">(</span><span class="va">mt_tally</span><span class="op">$</span><span class="va">nmf_matrix</span>, <span class="st">"~/test/test_sigminer"</span>,</span>
<span>  use_conda <span class="op">=</span> <span class="cn">FALSE</span>, py_path <span class="op">=</span> <span class="st">"/Users/wsx/anaconda3/bin/python"</span></span>
<span><span class="op">)</span></span></code></pre></div>
</div>
<div id="method-3-bootstrapped-nmf" class="section level4" number="3.3.2.3">
<h4>
<span class="header-section-number">3.3.2.3</span> Method 3: bootstrapped NMF<a class="anchor" aria-label="anchor" href="#method-3-bootstrapped-nmf"><i class="fas fa-link"></i></a>
</h4>
<div class="sourceCode" id="cb31"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co"># Same as</span></span>
<span><span class="co"># mt_sig3 &lt;- sig_unify_extract(</span></span>
<span><span class="co">#   cn_tally_W$nmf_matrix,</span></span>
<span><span class="co">#   range = 3:8,</span></span>
<span><span class="co">#   nrun = 10</span></span>
<span><span class="co">#   n_bootstrap = 5</span></span>
<span><span class="co"># )</span></span>
<span></span>
<span><span class="va">mt_sig3</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/pkg/sigminer/man/bp.html">bp_extract_signatures</a></span><span class="op">(</span></span>
<span>  <span class="va">cn_tally_W</span><span class="op">$</span><span class="va">nmf_matrix</span>,</span>
<span>  range <span class="op">=</span> <span class="fl">3</span><span class="op">:</span><span class="fl">8</span>,</span>
<span>  n_bootstrap <span class="op">=</span> <span class="fl">5</span>,</span>
<span>  n_nmf_run <span class="op">=</span> <span class="fl">10</span></span>
<span><span class="op">)</span></span></code></pre></div>
</div>
</div>
</div>
<div id="match-signatures" class="section level2" number="3.4">
<h2>
<span class="header-section-number">3.4</span> Match Signatures<a class="anchor" aria-label="anchor" href="#match-signatures"><i class="fas fa-link"></i></a>
</h2>
<p>After extracting signatures, we need to know their etiologies. This can be done by comparing the identified signatures and reference signatures from COSMIC database.</p>
<div class="sourceCode" id="cb32"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="va">sim</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/pkg/sigminer/man/get_sig_similarity.html">get_sig_similarity</a></span><span class="op">(</span><span class="va">mt_sig2</span><span class="op">)</span></span>
<span><span class="co">## -Comparing against COSMIC signatures</span></span>
<span><span class="co">## ------------------------------------</span></span>
<span><span class="co">## --Found Sig1 most similar to COSMIC_3</span></span>
<span><span class="co">##    Aetiology: defects in DNA-DSB repair by HR [similarity: 0.826]</span></span>
<span><span class="co">## --Found Sig2 most similar to COSMIC_1</span></span>
<span><span class="co">##    Aetiology: spontaneous deamination of 5-methylcytosine [similarity: 0.944]</span></span>
<span><span class="co">## --Found Sig3 most similar to COSMIC_2</span></span>
<span><span class="co">##    Aetiology: APOBEC Cytidine Deaminase (C&gt;T) [similarity: 0.838]</span></span>
<span><span class="co">## ------------------------------------</span></span>
<span><span class="co">## Return result invisiblely.</span></span></code></pre></div>
<p>The result object <code>sim</code> is a list.</p>
<div class="sourceCode" id="cb33"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="fu"><a href="https://rdrr.io/r/utils/str.html">str</a></span><span class="op">(</span><span class="va">sim</span><span class="op">)</span></span>
<span><span class="co">## List of 4</span></span>
<span><span class="co">##  $ similarity  : num [1:3, 1:30] 0.826 0.274 0.373 0.56 0.944 0.164 0.088 0.259 0.838 0.722 ...</span></span>
<span><span class="co">##   ..- attr(*, "dimnames")=List of 2</span></span>
<span><span class="co">##   .. ..$ : chr [1:3] "Sig1" "Sig2" "Sig3"</span></span>
<span><span class="co">##   .. ..$ : chr [1:30] "COSMIC_3" "COSMIC_1" "COSMIC_2" "COSMIC_4" ...</span></span>
<span><span class="co">##  $ aetiology_db:List of 1</span></span>
<span><span class="co">##   ..$ : chr [1:30] "spontaneous deamination of 5-methylcytosine" "APOBEC Cytidine Deaminase (C&gt;T)" "defects in DNA-DSB repair by HR" "exposure to tobacco (smoking) mutagens" ...</span></span>
<span><span class="co">##  $ best_match  :List of 3</span></span>
<span><span class="co">##   ..$ Sig1:List of 2</span></span>
<span><span class="co">##   .. ..$ aetiology : chr "defects in DNA-DSB repair by HR"</span></span>
<span><span class="co">##   .. ..$ best_match: chr "Best match: COSMIC_3 [similarity: 0.826]"</span></span>
<span><span class="co">##   ..$ Sig2:List of 2</span></span>
<span><span class="co">##   .. ..$ aetiology : chr "spontaneous deamination of 5-methylcytosine"</span></span>
<span><span class="co">##   .. ..$ best_match: chr "Best match: COSMIC_1 [similarity: 0.944]"</span></span>
<span><span class="co">##   ..$ Sig3:List of 2</span></span>
<span><span class="co">##   .. ..$ aetiology : chr "APOBEC Cytidine Deaminase (C&gt;T)"</span></span>
<span><span class="co">##   .. ..$ best_match: chr "Best match: COSMIC_2 [similarity: 0.838]"</span></span>
<span><span class="co">##  $ rss         : num [1:3, 1:30] 0.04294 0.00684 0.14741 0.24881 0.24076 ...</span></span>
<span><span class="co">##   ..- attr(*, "dimnames")=List of 2</span></span>
<span><span class="co">##   .. ..$ : chr [1:3] "Sig1" "Sig2" "Sig3"</span></span>
<span><span class="co">##   .. ..$ : chr [1:30] "COSMIC_1" "COSMIC_2" "COSMIC_3" "COSMIC_4" ...</span></span>
<span><span class="co">##  - attr(*, "class")= chr [1:2] "similarity" "list"</span></span></code></pre></div>
<p>From the result we can see that three signatures are properly matched to COSMIC reference signatures. If you find unknown signatures in your study, you should explore the etiologies by other analyses and even experiments.</p>
<p>The similarity matrix can be plotted.</p>
<div class="sourceCode" id="cb34"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="fu">pheatmap</span><span class="fu">::</span><span class="fu"><a href="https://rdrr.io/pkg/pheatmap/man/pheatmap.html">pheatmap</a></span><span class="op">(</span><span class="va">sim</span><span class="op">$</span><span class="va">similarity</span><span class="op">)</span></span></code></pre></div>
<div class="inline-figure"><img src="sigminer_files/figure-html/unnamed-chunk-46-1.png" width="95%"></div>
<p>You can also try the COSMIC signature database V3 with:</p>
<div class="sourceCode" id="cb35"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="va">sim_v3</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/pkg/sigminer/man/get_sig_similarity.html">get_sig_similarity</a></span><span class="op">(</span><span class="va">mt_sig2</span>, sig_db <span class="op">=</span> <span class="st">"SBS"</span><span class="op">)</span></span>
<span><span class="co">## -Comparing against COSMIC signatures</span></span>
<span><span class="co">## ------------------------------------</span></span>
<span><span class="co">## --Found Sig1 most similar to SBS3</span></span>
<span><span class="co">##    Aetiology: Defective homologous recombination DNA damage repair [similarity: 0.828]</span></span>
<span><span class="co">## --Found Sig2 most similar to SBS1</span></span>
<span><span class="co">##    Aetiology: Spontaneous deamination of 5-methylcytosine (clock-like signature) [similarity: 0.876]</span></span>
<span><span class="co">## --Found Sig3 most similar to SBS2</span></span>
<span><span class="co">##    Aetiology: Activity of APOBEC family of cytidine deaminases [similarity: 0.746]</span></span>
<span><span class="co">## ------------------------------------</span></span>
<span><span class="co">## Return result invisiblely.</span></span></code></pre></div>
</div>
<div id="reference-signature-fitting" class="section level2" number="3.5">
<h2>
<span class="header-section-number">3.5</span> Reference signature fitting<a class="anchor" aria-label="anchor" href="#reference-signature-fitting"><i class="fas fa-link"></i></a>
</h2>
<p>Besides <em>de novo</em> signature discovery shown in previous chapters, another common task is that
you have gotten some reference signatures (either from known database like COSMIC or <em>de novo</em> discovery step), you want to know how these signatures contribute (fit) in a sample. That’s the target of <code><a href="https://rdrr.io/pkg/sigminer/man/sig_fit.html">sig_fit()</a></code>.</p>
<p><code><a href="https://rdrr.io/pkg/sigminer/man/sig_fit.html">sig_fit()</a></code> uses multiple methods to compute exposure of pre-defined signatures from the spectrum of a (can be more) sample. Use <code><a href="https://rdrr.io/pkg/sigminer/man/sig_fit.html">?sig_fit</a></code> see more detail.</p>
<p>To show how this function works, we use a sample with maximum mutation counts as example data.</p>
<div class="sourceCode" id="cb36"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="va">i</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/which.min.html">which.max</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/apply.html">apply</a></span><span class="op">(</span><span class="va">mt_tally</span><span class="op">$</span><span class="va">nmf_matrix</span>, <span class="fl">1</span>, <span class="va">sum</span><span class="op">)</span><span class="op">)</span></span>
<span><span class="va">example_mat</span> <span class="op">&lt;-</span> <span class="va">mt_tally</span><span class="op">$</span><span class="va">nmf_matrix</span><span class="op">[</span><span class="va">i</span>, , drop <span class="op">=</span> <span class="cn">FALSE</span><span class="op">]</span> <span class="op"><a href="https://magrittr.tidyverse.org/reference/pipe.html">%&gt;%</a></span> <span class="fu"><a href="https://rdrr.io/r/base/t.html">t</a></span><span class="op">(</span><span class="op">)</span></span></code></pre></div>
<div class="sourceCode" id="cb37"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="fu"><a href="https://rdrr.io/r/utils/head.html">head</a></span><span class="op">(</span><span class="va">example_mat</span><span class="op">)</span></span>
<span><span class="co">##         TCGA-A8-A09G-01A-21W-A019-09</span></span>
<span><span class="co">## A[T&gt;C]A                            1</span></span>
<span><span class="co">## C[T&gt;C]A                            0</span></span>
<span><span class="co">## G[T&gt;C]A                            1</span></span>
<span><span class="co">## T[T&gt;C]A                            1</span></span>
<span><span class="co">## A[C&gt;T]A                            5</span></span>
<span><span class="co">## C[C&gt;T]A                            3</span></span></code></pre></div>
<div id="fit-signatures-from-reference-signature-databasase" class="section level3" number="3.5.1">
<h3>
<span class="header-section-number">3.5.1</span> Fit signatures from reference signature databasase<a class="anchor" aria-label="anchor" href="#fit-signatures-from-reference-signature-databasase"><i class="fas fa-link"></i></a>
</h3>
<p>For SBS signatures, users may want to directly use reference signatures from COSMIC database.</p>
<div class="sourceCode" id="cb38"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="fu"><a href="https://rdrr.io/pkg/sigminer/man/sig_fit.html">sig_fit</a></span><span class="op">(</span><span class="va">example_mat</span>, sig_index <span class="op">=</span> <span class="fl">1</span><span class="op">:</span><span class="fl">30</span><span class="op">)</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:15]: Started.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:51:15]: Signature index detected.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:15]: Checking signature database in package.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:15]: Checking signature index.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:15]: Valid index for db 'legacy':</span></span>
<span><span class="co">## 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30</span></span>
<span><span class="co">## ✓ [2021-12-04 23:51:15]: Database and index checked.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:51:15]: Signature normalized.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:15]: Checking row number for catalog matrix and signature matrix.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:51:15]: Checked.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:15]: Checking rownames for catalog matrix and signature matrix.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:15]: Matrix V and W don't have same orders. Try reordering...</span></span>
<span><span class="co">## ✓ [2021-12-04 23:51:15]: Checked.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:51:15]: Method 'QP' detected.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:51:15]: Corresponding function generated.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:15]: Calling function.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:15]: Fitting sample: TCGA-A8-A09G-01A-21W-A019-09</span></span>
<span><span class="co">## ✓ [2021-12-04 23:51:15]: Done.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:15]: Generating output signature exposures.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:51:15]: Done.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:15]: 0.046 secs elapsed.</span></span>
<span><span class="co">##           TCGA-A8-A09G-01A-21W-A019-09</span></span>
<span><span class="co">## COSMIC_1                     24.215933</span></span>
<span><span class="co">## COSMIC_2                    127.164108</span></span>
<span><span class="co">## COSMIC_3                      0.000000</span></span>
<span><span class="co">## COSMIC_4                      0.000000</span></span>
<span><span class="co">## COSMIC_5                      0.000000</span></span>
<span><span class="co">## COSMIC_6                      0.000000</span></span>
<span><span class="co">## COSMIC_7                      4.907674</span></span>
<span><span class="co">## COSMIC_8                      0.000000</span></span>
<span><span class="co">## COSMIC_9                      0.000000</span></span>
<span><span class="co">## COSMIC_10                     3.584276</span></span>
<span><span class="co">## COSMIC_11                     0.000000</span></span>
<span><span class="co">## COSMIC_12                    11.062526</span></span>
<span><span class="co">## COSMIC_13                   168.298139</span></span>
<span><span class="co">## COSMIC_14                     0.000000</span></span>
<span><span class="co">## COSMIC_15                     0.000000</span></span>
<span><span class="co">## COSMIC_16                     0.000000</span></span>
<span><span class="co">## COSMIC_17                     5.578495</span></span>
<span><span class="co">## COSMIC_18                     0.000000</span></span>
<span><span class="co">## COSMIC_19                     0.000000</span></span>
<span><span class="co">## COSMIC_20                     0.000000</span></span>
<span><span class="co">## COSMIC_21                     0.000000</span></span>
<span><span class="co">## COSMIC_22                     0.000000</span></span>
<span><span class="co">## COSMIC_23                     0.000000</span></span>
<span><span class="co">## COSMIC_24                    12.084656</span></span>
<span><span class="co">## COSMIC_25                     0.000000</span></span>
<span><span class="co">## COSMIC_26                     0.000000</span></span>
<span><span class="co">## COSMIC_27                     0.000000</span></span>
<span><span class="co">## COSMIC_28                     0.000000</span></span>
<span><span class="co">## COSMIC_29                     0.000000</span></span>
<span><span class="co">## COSMIC_30                     0.104192</span></span></code></pre></div>
<blockquote>
<p>At default, COSMIC v2 signature database with 30 reference signatures is used (i.e. <code>sig_db = "legacy"</code>). Set <code>sig_db = "SBS"</code> for COSMIC v3 signature database.
That’s it!</p>
</blockquote>
<p>You can set <code>type = "relative"</code> for getting relative exposure.</p>
<div class="sourceCode" id="cb39"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="fu"><a href="https://rdrr.io/pkg/sigminer/man/sig_fit.html">sig_fit</a></span><span class="op">(</span><span class="va">example_mat</span>, sig_index <span class="op">=</span> <span class="fl">1</span><span class="op">:</span><span class="fl">30</span>, type <span class="op">=</span> <span class="st">"relative"</span><span class="op">)</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:15]: Started.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:51:15]: Signature index detected.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:15]: Checking signature database in package.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:15]: Checking signature index.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:15]: Valid index for db 'legacy':</span></span>
<span><span class="co">## 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30</span></span>
<span><span class="co">## ✓ [2021-12-04 23:51:15]: Database and index checked.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:51:15]: Signature normalized.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:15]: Checking row number for catalog matrix and signature matrix.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:51:15]: Checked.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:15]: Checking rownames for catalog matrix and signature matrix.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:15]: Matrix V and W don't have same orders. Try reordering...</span></span>
<span><span class="co">## ✓ [2021-12-04 23:51:15]: Checked.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:51:15]: Method 'QP' detected.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:51:15]: Corresponding function generated.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:15]: Calling function.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:15]: Fitting sample: TCGA-A8-A09G-01A-21W-A019-09</span></span>
<span><span class="co">## ✓ [2021-12-04 23:51:15]: Done.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:15]: Generating output signature exposures.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:51:15]: Done.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:15]: 0.034 secs elapsed.</span></span>
<span><span class="co">##           TCGA-A8-A09G-01A-21W-A019-09</span></span>
<span><span class="co">## COSMIC_1                      0.067832</span></span>
<span><span class="co">## COSMIC_2                      0.356202</span></span>
<span><span class="co">## COSMIC_3                      0.000000</span></span>
<span><span class="co">## COSMIC_4                      0.000000</span></span>
<span><span class="co">## COSMIC_5                      0.000000</span></span>
<span><span class="co">## COSMIC_6                      0.000000</span></span>
<span><span class="co">## COSMIC_7                      0.013747</span></span>
<span><span class="co">## COSMIC_8                      0.000000</span></span>
<span><span class="co">## COSMIC_9                      0.000000</span></span>
<span><span class="co">## COSMIC_10                     0.010040</span></span>
<span><span class="co">## COSMIC_11                     0.000000</span></span>
<span><span class="co">## COSMIC_12                     0.030987</span></span>
<span><span class="co">## COSMIC_13                     0.471423</span></span>
<span><span class="co">## COSMIC_14                     0.000000</span></span>
<span><span class="co">## COSMIC_15                     0.000000</span></span>
<span><span class="co">## COSMIC_16                     0.000000</span></span>
<span><span class="co">## COSMIC_17                     0.015626</span></span>
<span><span class="co">## COSMIC_18                     0.000000</span></span>
<span><span class="co">## COSMIC_19                     0.000000</span></span>
<span><span class="co">## COSMIC_20                     0.000000</span></span>
<span><span class="co">## COSMIC_21                     0.000000</span></span>
<span><span class="co">## COSMIC_22                     0.000000</span></span>
<span><span class="co">## COSMIC_23                     0.000000</span></span>
<span><span class="co">## COSMIC_24                     0.033851</span></span>
<span><span class="co">## COSMIC_25                     0.000000</span></span>
<span><span class="co">## COSMIC_26                     0.000000</span></span>
<span><span class="co">## COSMIC_27                     0.000000</span></span>
<span><span class="co">## COSMIC_28                     0.000000</span></span>
<span><span class="co">## COSMIC_29                     0.000000</span></span>
<span><span class="co">## COSMIC_30                     0.000292</span></span></code></pre></div>
<p>For multiple samples, you can return a <code>data.table</code>, it can be easier to integrate with other information in R.</p>
<div class="sourceCode" id="cb40"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="fu"><a href="https://rdrr.io/pkg/sigminer/man/sig_fit.html">sig_fit</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/t.html">t</a></span><span class="op">(</span><span class="va">mt_tally</span><span class="op">$</span><span class="va">nmf_matrix</span><span class="op">[</span><span class="fl">1</span><span class="op">:</span><span class="fl">5</span>, <span class="op">]</span><span class="op">)</span>, sig_index <span class="op">=</span> <span class="fl">1</span><span class="op">:</span><span class="fl">30</span>, return_class <span class="op">=</span> <span class="st">"data.table"</span>, rel_threshold <span class="op">=</span> <span class="fl">0.05</span><span class="op">)</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:15]: Started.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:51:15]: Signature index detected.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:15]: Checking signature database in package.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:15]: Checking signature index.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:15]: Valid index for db 'legacy':</span></span>
<span><span class="co">## 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30</span></span>
<span><span class="co">## ✓ [2021-12-04 23:51:15]: Database and index checked.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:51:15]: Signature normalized.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:15]: Checking row number for catalog matrix and signature matrix.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:51:15]: Checked.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:15]: Checking rownames for catalog matrix and signature matrix.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:15]: Matrix V and W don't have same orders. Try reordering...</span></span>
<span><span class="co">## ✓ [2021-12-04 23:51:15]: Checked.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:51:15]: Method 'QP' detected.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:51:15]: Corresponding function generated.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:15]: Calling function.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:15]: Fitting sample: TCGA-A1-A0SH-01A-11D-A099-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:15]: Fitting sample: TCGA-A2-A04N-01A-11D-A10Y-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:15]: Fitting sample: TCGA-A2-A0CP-01A-11W-A050-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:15]: Fitting sample: TCGA-A2-A0EP-01A-52D-A22X-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:15]: Fitting sample: TCGA-A2-A0EV-01A-11W-A050-09</span></span>
<span><span class="co">## ✓ [2021-12-04 23:51:15]: Done.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:15]: Generating output signature exposures.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:51:15]: Done.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:15]: 0.054 secs elapsed.</span></span>
<span><span class="co">##                          sample  COSMIC_1  COSMIC_2 COSMIC_3 COSMIC_4 COSMIC_5</span></span>
<span><span class="co">## 1: TCGA-A1-A0SH-01A-11D-A099-09  0.000000 37.420603 13.78689 0.000000        0</span></span>
<span><span class="co">## 2: TCGA-A2-A04N-01A-11D-A10Y-09 20.039543  2.888675  0.00000 0.000000        0</span></span>
<span><span class="co">## 3: TCGA-A2-A0CP-01A-11W-A050-09  3.648658  0.000000  0.00000 7.083113        0</span></span>
<span><span class="co">## 4: TCGA-A2-A0EP-01A-52D-A22X-09  0.000000  0.000000  0.00000 2.492218        0</span></span>
<span><span class="co">## 5: TCGA-A2-A0EV-01A-11W-A050-09  6.458422  0.000000 14.83102 0.000000        0</span></span>
<span><span class="co">##    COSMIC_6  COSMIC_7 COSMIC_8 COSMIC_9 COSMIC_10 COSMIC_11 COSMIC_12 COSMIC_13</span></span>
<span><span class="co">## 1: 12.93472 21.332013  0.00000        0  0.000000         0  0.000000 31.306430</span></span>
<span><span class="co">## 2:  0.00000  6.865345 12.11501        0  0.000000         0  0.000000  0.000000</span></span>
<span><span class="co">## 3:  0.00000 10.348536  0.00000        0  0.000000         0  0.000000  0.000000</span></span>
<span><span class="co">## 4:  0.00000  2.156319  0.00000        0  0.000000         0  1.334731  4.654227</span></span>
<span><span class="co">## 5: 14.78142 21.963952  0.00000        0  7.978962         0  0.000000  5.713563</span></span>
<span><span class="co">##    COSMIC_14 COSMIC_15 COSMIC_16 COSMIC_17 COSMIC_18 COSMIC_19 COSMIC_20</span></span>
<span><span class="co">## 1:  0.000000   0.00000         0         0 12.007682         0  0.000000</span></span>
<span><span class="co">## 2:  0.000000   0.00000         0         0  0.000000         0  7.516444</span></span>
<span><span class="co">## 3:  0.000000  18.37734         0         0  4.384106         0  0.000000</span></span>
<span><span class="co">## 4:  6.728415   0.00000         0         0  0.000000         0  0.000000</span></span>
<span><span class="co">## 5:  0.000000   0.00000         0         0  0.000000         0  0.000000</span></span>
<span><span class="co">##    COSMIC_21 COSMIC_22 COSMIC_23 COSMIC_24 COSMIC_25 COSMIC_26 COSMIC_27</span></span>
<span><span class="co">## 1:  0.000000         0   0.00000         0         0         0         0</span></span>
<span><span class="co">## 2:  0.000000         0   0.00000         0         0         0         0</span></span>
<span><span class="co">## 3:  0.000000         0   0.00000         0         0         0         0</span></span>
<span><span class="co">## 4:  0.000000         0   1.26778         0         0         0         0</span></span>
<span><span class="co">## 5:  4.311951         0   0.00000         0         0         0         0</span></span>
<span><span class="co">##    COSMIC_28 COSMIC_29 COSMIC_30</span></span>
<span><span class="co">## 1:         0  0.000000         0</span></span>
<span><span class="co">## 2:         0  0.000000         0</span></span>
<span><span class="co">## 3:         0  4.776321         0</span></span>
<span><span class="co">## 4:         0  0.000000         0</span></span>
<span><span class="co">## 5:         0  0.000000         0</span></span></code></pre></div>
<p>When you set multiple signatures, we recommend setting <code>rel_threshold</code> option, which will set exposure of a signature to <code>0</code> if its relative exposure in a sample less than the <code>rel_threshold</code>.</p>
</div>
<div id="fit-custom-signatures" class="section level3" number="3.5.2">
<h3>
<span class="header-section-number">3.5.2</span> Fit custom signatures<a class="anchor" aria-label="anchor" href="#fit-custom-signatures"><i class="fas fa-link"></i></a>
</h3>
<p>We have already determined the SBS signatures before. Here we can set them to <code>sig</code> option.</p>
<div class="sourceCode" id="cb41"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="fu"><a href="https://rdrr.io/pkg/sigminer/man/sig_fit.html">sig_fit</a></span><span class="op">(</span><span class="va">example_mat</span>, sig <span class="op">=</span> <span class="va">mt_sig2</span><span class="op">)</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:15]: Started.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:15]: Signature index not detected.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:51:15]: Signature object detected.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:51:15]: Database and index checked.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:51:15]: Signature normalized.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:15]: Checking row number for catalog matrix and signature matrix.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:51:15]: Checked.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:15]: Checking rownames for catalog matrix and signature matrix.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:51:15]: Checked.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:51:15]: Method 'QP' detected.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:51:15]: Corresponding function generated.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:15]: Calling function.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:15]: Fitting sample: TCGA-A8-A09G-01A-21W-A019-09</span></span>
<span><span class="co">## ✓ [2021-12-04 23:51:15]: Done.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:15]: Generating output signature exposures.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:51:15]: Done.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:15]: 0.03 secs elapsed.</span></span>
<span><span class="co">##      TCGA-A8-A09G-01A-21W-A019-09</span></span>
<span><span class="co">## Sig1                            0</span></span>
<span><span class="co">## Sig2                            0</span></span>
<span><span class="co">## Sig3                          357</span></span></code></pre></div>
</div>
<div id="performance-comparison" class="section level3" number="3.5.3">
<h3>
<span class="header-section-number">3.5.3</span> Performance comparison<a class="anchor" aria-label="anchor" href="#performance-comparison"><i class="fas fa-link"></i></a>
</h3>
<p>Now that we can use <code>sig_fit</code> for getting optimal exposures, we can compare the RSS between <strong>raw matrix</strong> and the <strong>reconstructed matrix</strong> either by NMF and <code><a href="https://rdrr.io/pkg/sigminer/man/sig_fit.html">sig_fit()</a></code>.</p>
<p>i.e. </p>
<p><span class="math display">\[
RSS = \sum(\hat H - H)^2
\]</span></p>
<div class="sourceCode" id="cb42"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co">## Exposure got from NMF</span></span>
<span><span class="fu"><a href="https://rdrr.io/r/base/sum.html">sum</a></span><span class="op">(</span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/apply.html">apply</a></span><span class="op">(</span><span class="va">mt_sig2</span><span class="op">$</span><span class="va">Signature</span>, <span class="fl">2</span>, <span class="kw">function</span><span class="op">(</span><span class="va">x</span><span class="op">)</span> <span class="va">x</span> <span class="op">/</span> <span class="fu"><a href="https://rdrr.io/r/base/sum.html">sum</a></span><span class="op">(</span><span class="va">x</span><span class="op">)</span><span class="op">)</span> <span class="op"><a href="https://rdrr.io/r/base/matmult.html">%*%</a></span> <span class="va">mt_sig2</span><span class="op">$</span><span class="va">Exposure</span> <span class="op">-</span> <span class="fu"><a href="https://rdrr.io/r/base/t.html">t</a></span><span class="op">(</span><span class="va">mt_tally</span><span class="op">$</span><span class="va">nmf_matrix</span><span class="op">)</span><span class="op">)</span><span class="op">^</span><span class="fl">2</span><span class="op">)</span></span>
<span><span class="co">## [1] 8890.449</span></span></code></pre></div>
<div class="sourceCode" id="cb43"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co">## Exposure optimized by sig_fit</span></span>
<span><span class="va">H_estimate</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/apply.html">apply</a></span><span class="op">(</span><span class="va">mt_sig2</span><span class="op">$</span><span class="va">Signature</span>, <span class="fl">2</span>, <span class="kw">function</span><span class="op">(</span><span class="va">x</span><span class="op">)</span> <span class="va">x</span> <span class="op">/</span> <span class="fu"><a href="https://rdrr.io/r/base/sum.html">sum</a></span><span class="op">(</span><span class="va">x</span><span class="op">)</span><span class="op">)</span> <span class="op"><a href="https://rdrr.io/r/base/matmult.html">%*%</a></span> <span class="fu"><a href="https://rdrr.io/pkg/sigminer/man/sig_fit.html">sig_fit</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/t.html">t</a></span><span class="op">(</span><span class="va">mt_tally</span><span class="op">$</span><span class="va">nmf_matrix</span><span class="op">)</span>, sig <span class="op">=</span> <span class="va">mt_sig2</span><span class="op">)</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Started.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Signature index not detected.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:51:16]: Signature object detected.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:51:16]: Database and index checked.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:51:16]: Signature normalized.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Checking row number for catalog matrix and signature matrix.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:51:16]: Checked.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Checking rownames for catalog matrix and signature matrix.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:51:16]: Checked.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:51:16]: Method 'QP' detected.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:51:16]: Corresponding function generated.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Calling function.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-A1-A0SH-01A-11D-A099-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-A2-A04N-01A-11D-A10Y-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-A2-A0CP-01A-11W-A050-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-A2-A0EP-01A-52D-A22X-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-A2-A0EV-01A-11W-A050-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-A2-A0SX-01A-12D-A099-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-A2-A0T7-01A-21D-A099-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-A2-A0YF-01A-21D-A10G-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-A2-A25F-01A-11D-A167-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-A2-A3XW-01A-11D-A23C-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-A2-A4S1-01A-21D-A25Q-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-A7-A0D9-01A-31W-A071-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-A7-A13F-01A-11D-A12Q-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-A7-A5ZV-01A-11D-A28B-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-A8-A06P-01A-11W-A019-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-A8-A076-01A-21W-A019-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-A8-A07W-01A-11W-A019-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-A8-A084-01A-21W-A019-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-A8-A08S-01A-11W-A050-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-A8-A09G-01A-21W-A019-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-A8-A0A4-01A-11W-A019-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-A8-A0AB-01A-11W-A050-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-AC-A2B8-01A-11D-A17D-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-AC-A2FO-01A-11D-A17W-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-AC-A3YI-01A-21D-A23C-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-AC-A8OS-01A-12D-A41F-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-AN-A0FK-01A-11W-A050-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-AN-A0FT-01A-11W-A050-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-AN-A0XO-01A-11D-A10G-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-AO-A1KS-01A-11D-A13L-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-AQ-A54O-01A-11D-A25Q-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-AQ-A7U7-01A-22D-A351-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-AR-A0TP-01A-11D-A099-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-AR-A0U3-01A-11D-A10G-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-AR-A1AH-01A-11D-A12B-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-AR-A1AJ-01A-21D-A12Q-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-AR-A1AN-01A-11D-A12Q-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-AR-A24N-01A-11D-A167-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-AR-A252-01A-11D-A167-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-AR-A2LL-01A-11D-A17W-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-AR-A2LO-01A-31D-A18P-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-B6-A0IE-01A-11W-A050-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-B6-A0IM-01A-11W-A050-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-B6-A0IP-01A-11D-A045-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-B6-A0RV-01A-11D-A099-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-B6-A0WZ-01A-11D-A10G-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-B6-A0X1-01A-11D-A10G-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-B6-A1KC-01B-11D-A159-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-B6-A401-01A-11D-A23C-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-B6-A40C-01A-11D-A23C-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-BH-A0AV-01A-31D-A10Y-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-BH-A0BT-01A-11D-A12Q-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-BH-A0DL-01A-11D-A10Y-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-BH-A0DO-01B-11D-A12B-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-BH-A0DT-01A-21D-A12B-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-BH-A0GY-01A-11W-A071-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-BH-A0H6-01A-21W-A071-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-BH-A18K-01A-11D-A12B-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-BH-A1FU-01A-11D-A14G-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-BH-A202-01A-11D-A14K-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-BH-A5IZ-01A-11D-A27P-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-BH-A6R8-01A-21D-A33E-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-BH-A8G0-01A-11D-A351-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-C8-A131-01A-11D-A10Y-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-D8-A147-01A-11D-A10Y-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-D8-A1JG-01B-11D-A13L-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-D8-A1JH-01A-11D-A188-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-D8-A1JJ-01A-31D-A14K-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-D8-A1JT-01A-31D-A13L-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-D8-A1JU-01A-11D-A13L-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-D8-A1X7-01A-11D-A14K-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-D8-A1X8-01A-11D-A14K-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-D8-A1XL-01A-11D-A14K-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-D8-A27V-01A-12D-A17D-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-E2-A108-01A-13D-A10M-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-E2-A10F-01A-11D-A10M-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-E2-A14T-01A-11D-A10Y-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-E2-A152-01A-11D-A12B-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-E2-A15D-01A-11D-A10Y-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-E2-A15L-01A-11D-A12B-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-E2-A1BD-01A-11D-A12Q-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-E2-A1IH-01A-11D-A188-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-E2-A1II-01A-11D-A142-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-E2-A1IJ-01A-11D-A142-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-E2-A1L6-01A-11D-A13L-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-E2-A9RU-01A-11D-A41F-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-E9-A1NE-01A-21D-A14K-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-E9-A22A-01A-11D-A159-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-E9-A22E-01A-11D-A159-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-E9-A3QA-01A-61D-A228-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-E9-A5FL-01A-11D-A27P-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-EW-A1PA-01A-11D-A142-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-EW-A1PH-01A-11D-A14K-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-GM-A2DB-01A-31D-A19Y-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-LD-A9QF-01A-32D-A41F-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-LL-A5YP-01A-21D-A28B-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-LL-A73Z-01A-11D-A32I-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-OL-A5RY-01A-21D-A28B-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-PE-A5DD-01A-12D-A27P-09</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-S3-AA17-01A-11D-A41F-09</span></span>
<span><span class="co">## ✓ [2021-12-04 23:51:16]: Done.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Generating output signature exposures.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:51:16]: Done.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: 0.19 secs elapsed.</span></span>
<span><span class="va">H_estimate</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/apply.html">apply</a></span><span class="op">(</span><span class="va">H_estimate</span>, <span class="fl">2</span>, <span class="kw">function</span><span class="op">(</span><span class="va">x</span><span class="op">)</span> <span class="fu"><a href="https://rdrr.io/r/base/ifelse.html">ifelse</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/is.finite.html">is.nan</a></span><span class="op">(</span><span class="va">x</span><span class="op">)</span>, <span class="fl">0</span>, <span class="va">x</span><span class="op">)</span><span class="op">)</span></span>
<span><span class="va">H_real</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/t.html">t</a></span><span class="op">(</span><span class="va">mt_tally</span><span class="op">$</span><span class="va">nmf_matrix</span><span class="op">)</span></span>
<span><span class="fu"><a href="https://rdrr.io/r/base/sum.html">sum</a></span><span class="op">(</span><span class="op">(</span><span class="va">H_estimate</span> <span class="op">-</span> <span class="va">H_real</span><span class="op">)</span><span class="op">^</span><span class="fl">2</span><span class="op">)</span></span>
<span><span class="co">## [1] 8237.832</span></span></code></pre></div>
</div>
<div id="estimate-exposureactivity-stability-by-bootstrapping" class="section level3" number="3.5.4">
<h3>
<span class="header-section-number">3.5.4</span> Estimate exposure/activity stability by bootstrapping<a class="anchor" aria-label="anchor" href="#estimate-exposureactivity-stability-by-bootstrapping"><i class="fas fa-link"></i></a>
</h3>
<p>This feature is based on <code><a href="https://rdrr.io/pkg/sigminer/man/sig_fit.html">sig_fit()</a></code>, it uses the resampling data of original input and runs <code><a href="https://rdrr.io/pkg/sigminer/man/sig_fit.html">sig_fit()</a></code> multiple times to estimate the exposure. Bootstrapped replicates &gt;= 100 is recommended, here I just use 10 times for illustration.</p>
<div class="sourceCode" id="cb44"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="va">bt_result</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/pkg/sigminer/man/sig_fit_bootstrap_batch.html">sig_fit_bootstrap_batch</a></span><span class="op">(</span><span class="va">example_mat</span>, sig <span class="op">=</span> <span class="va">mt_sig2</span>, n <span class="op">=</span> <span class="fl">10</span><span class="op">)</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Batch Bootstrap Signature Exposure Analysis Started.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Samples to be filtered out:</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Finding optimal exposures (&amp;errors) for different methods.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Calling method `QP`.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Started.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Signature index not detected.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:51:16]: Signature object detected.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:51:16]: Database and index checked.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:51:16]: Signature normalized.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Checking row number for catalog matrix and signature matrix.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:51:16]: Checked.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Checking rownames for catalog matrix and signature matrix.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:51:16]: Checked.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:51:16]: Method 'QP' detected.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:51:16]: Corresponding function generated.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Calling function.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Fitting sample: TCGA-A8-A09G-01A-21W-A019-09</span></span>
<span><span class="co">## ✓ [2021-12-04 23:51:16]: Done.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Generating output signature exposures.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:51:16]: Done.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Calculating errors (Frobenius Norm).</span></span>
<span><span class="co">## ✓ [2021-12-04 23:51:16]: Done.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: 0.045 secs elapsed.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Getting bootstrap exposures (&amp;errors/similarity) for different methods.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: This step is time consuming, please be patient.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:16]: Processing sample `TCGA-A8-A09G-01A-21W-A019-09`.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:51:17]: Gotten.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:17]: Reporting p values...</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:17]: Started.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:51:17]: Batch mode enabled.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:51:17]: Done.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:17]: 0.016 secs elapsed.</span></span>
<span><span class="co">## ✓ [2021-12-04 23:51:17]: Done.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:17]: Cleaning results...</span></span>
<span><span class="co">## ✓ [2021-12-04 23:51:17]: Outputing.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:17]: Total 1.181 secs elapsed.</span></span>
<span><span class="va">bt_result</span></span>
<span><span class="co">## $expo</span></span>
<span><span class="co">##     method                       sample  sig   exposure    type</span></span>
<span><span class="co">##  1:     QP TCGA-A8-A09G-01A-21W-A019-09 Sig1   0.000000 optimal</span></span>
<span><span class="co">##  2:     QP TCGA-A8-A09G-01A-21W-A019-09 Sig2   0.000000 optimal</span></span>
<span><span class="co">##  3:     QP TCGA-A8-A09G-01A-21W-A019-09 Sig3 357.000000 optimal</span></span>
<span><span class="co">##  4:     QP TCGA-A8-A09G-01A-21W-A019-09 Sig1   0.571227   Rep_1</span></span>
<span><span class="co">##  5:     QP TCGA-A8-A09G-01A-21W-A019-09 Sig2  11.191972   Rep_1</span></span>
<span><span class="co">##  6:     QP TCGA-A8-A09G-01A-21W-A019-09 Sig3 345.236801   Rep_1</span></span>
<span><span class="co">##  7:     QP TCGA-A8-A09G-01A-21W-A019-09 Sig1  10.758870   Rep_2</span></span>
<span><span class="co">##  8:     QP TCGA-A8-A09G-01A-21W-A019-09 Sig2   0.000000   Rep_2</span></span>
<span><span class="co">##  9:     QP TCGA-A8-A09G-01A-21W-A019-09 Sig3 346.241130   Rep_2</span></span>
<span><span class="co">## 10:     QP TCGA-A8-A09G-01A-21W-A019-09 Sig1   0.000000   Rep_3</span></span>
<span><span class="co">## 11:     QP TCGA-A8-A09G-01A-21W-A019-09 Sig2   2.037155   Rep_3</span></span>
<span><span class="co">## 12:     QP TCGA-A8-A09G-01A-21W-A019-09 Sig3 354.962845   Rep_3</span></span>
<span><span class="co">## 13:     QP TCGA-A8-A09G-01A-21W-A019-09 Sig1   0.000000   Rep_4</span></span>
<span><span class="co">## 14:     QP TCGA-A8-A09G-01A-21W-A019-09 Sig2   0.000000   Rep_4</span></span>
<span><span class="co">## 15:     QP TCGA-A8-A09G-01A-21W-A019-09 Sig3 357.000000   Rep_4</span></span>
<span><span class="co">## 16:     QP TCGA-A8-A09G-01A-21W-A019-09 Sig1   0.973130   Rep_5</span></span>
<span><span class="co">## 17:     QP TCGA-A8-A09G-01A-21W-A019-09 Sig2   2.350855   Rep_5</span></span>
<span><span class="co">## 18:     QP TCGA-A8-A09G-01A-21W-A019-09 Sig3 353.676014   Rep_5</span></span>
<span><span class="co">## 19:     QP TCGA-A8-A09G-01A-21W-A019-09 Sig1   5.262795   Rep_6</span></span>
<span><span class="co">## 20:     QP TCGA-A8-A09G-01A-21W-A019-09 Sig2  12.971145   Rep_6</span></span>
<span><span class="co">## 21:     QP TCGA-A8-A09G-01A-21W-A019-09 Sig3 338.766060   Rep_6</span></span>
<span><span class="co">## 22:     QP TCGA-A8-A09G-01A-21W-A019-09 Sig1   0.000000   Rep_7</span></span>
<span><span class="co">## 23:     QP TCGA-A8-A09G-01A-21W-A019-09 Sig2   0.000000   Rep_7</span></span>
<span><span class="co">## 24:     QP TCGA-A8-A09G-01A-21W-A019-09 Sig3 357.000000   Rep_7</span></span>
<span><span class="co">## 25:     QP TCGA-A8-A09G-01A-21W-A019-09 Sig1   0.917790   Rep_8</span></span>
<span><span class="co">## 26:     QP TCGA-A8-A09G-01A-21W-A019-09 Sig2   0.384690   Rep_8</span></span>
<span><span class="co">## 27:     QP TCGA-A8-A09G-01A-21W-A019-09 Sig3 355.697520   Rep_8</span></span>
<span><span class="co">## 28:     QP TCGA-A8-A09G-01A-21W-A019-09 Sig1   0.000000   Rep_9</span></span>
<span><span class="co">## 29:     QP TCGA-A8-A09G-01A-21W-A019-09 Sig2  13.629205   Rep_9</span></span>
<span><span class="co">## 30:     QP TCGA-A8-A09G-01A-21W-A019-09 Sig3 343.370795   Rep_9</span></span>
<span><span class="co">## 31:     QP TCGA-A8-A09G-01A-21W-A019-09 Sig1   0.000000  Rep_10</span></span>
<span><span class="co">## 32:     QP TCGA-A8-A09G-01A-21W-A019-09 Sig2   0.000000  Rep_10</span></span>
<span><span class="co">## 33:     QP TCGA-A8-A09G-01A-21W-A019-09 Sig3 357.000000  Rep_10</span></span>
<span><span class="co">##     method                       sample  sig   exposure    type</span></span>
<span><span class="co">## </span></span>
<span><span class="co">## $error</span></span>
<span><span class="co">##     method                       sample errors    type</span></span>
<span><span class="co">##  1:     QP TCGA-A8-A09G-01A-21W-A019-09 18.313 optimal</span></span>
<span><span class="co">##  2:     QP TCGA-A8-A09G-01A-21W-A019-09 18.930   Rep_1</span></span>
<span><span class="co">##  3:     QP TCGA-A8-A09G-01A-21W-A019-09 18.824   Rep_2</span></span>
<span><span class="co">##  4:     QP TCGA-A8-A09G-01A-21W-A019-09 18.353   Rep_3</span></span>
<span><span class="co">##  5:     QP TCGA-A8-A09G-01A-21W-A019-09 18.313   Rep_4</span></span>
<span><span class="co">##  6:     QP TCGA-A8-A09G-01A-21W-A019-09 18.392   Rep_5</span></span>
<span><span class="co">##  7:     QP TCGA-A8-A09G-01A-21W-A019-09 19.563   Rep_6</span></span>
<span><span class="co">##  8:     QP TCGA-A8-A09G-01A-21W-A019-09 18.313   Rep_7</span></span>
<span><span class="co">##  9:     QP TCGA-A8-A09G-01A-21W-A019-09 18.337   Rep_8</span></span>
<span><span class="co">## 10:     QP TCGA-A8-A09G-01A-21W-A019-09 19.122   Rep_9</span></span>
<span><span class="co">## 11:     QP TCGA-A8-A09G-01A-21W-A019-09 18.313  Rep_10</span></span>
<span><span class="co">## </span></span>
<span><span class="co">## $cosine</span></span>
<span><span class="co">##     method                       sample   cosine    type</span></span>
<span><span class="co">##  1:     QP TCGA-A8-A09G-01A-21W-A019-09 0.988618 optimal</span></span>
<span><span class="co">##  2:     QP TCGA-A8-A09G-01A-21W-A019-09 0.989479   Rep_1</span></span>
<span><span class="co">##  3:     QP TCGA-A8-A09G-01A-21W-A019-09 0.966835   Rep_2</span></span>
<span><span class="co">##  4:     QP TCGA-A8-A09G-01A-21W-A019-09 0.972369   Rep_3</span></span>
<span><span class="co">##  5:     QP TCGA-A8-A09G-01A-21W-A019-09 0.971626   Rep_4</span></span>
<span><span class="co">##  6:     QP TCGA-A8-A09G-01A-21W-A019-09 0.982418   Rep_5</span></span>
<span><span class="co">##  7:     QP TCGA-A8-A09G-01A-21W-A019-09 0.984565   Rep_6</span></span>
<span><span class="co">##  8:     QP TCGA-A8-A09G-01A-21W-A019-09 0.984212   Rep_7</span></span>
<span><span class="co">##  9:     QP TCGA-A8-A09G-01A-21W-A019-09 0.982291   Rep_8</span></span>
<span><span class="co">## 10:     QP TCGA-A8-A09G-01A-21W-A019-09 0.987838   Rep_9</span></span>
<span><span class="co">## 11:     QP TCGA-A8-A09G-01A-21W-A019-09 0.974672  Rep_10</span></span>
<span><span class="co">## </span></span>
<span><span class="co">## $p_val</span></span>
<span><span class="co">##                          sample method threshold  sig      p_value</span></span>
<span><span class="co">## 1: TCGA-A8-A09G-01A-21W-A019-09     QP      0.05 Sig1 9.999999e-01</span></span>
<span><span class="co">## 2: TCGA-A8-A09G-01A-21W-A019-09     QP      0.05 Sig2 9.999783e-01</span></span>
<span><span class="co">## 3: TCGA-A8-A09G-01A-21W-A019-09     QP      0.05 Sig3 4.978413e-17</span></span></code></pre></div>
<p>You can plot the result very easily with functions provided by <strong>sigminer</strong>.</p>
<div class="sourceCode" id="cb45"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="fu"><a href="https://rdrr.io/pkg/sigminer/man/show_sig_bootstrap.html">show_sig_bootstrap_exposure</a></span><span class="op">(</span><span class="va">bt_result</span>, sample <span class="op">=</span> <span class="st">"TCGA-A8-A09G-01A-21W-A019-09"</span><span class="op">)</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:17]: Started.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:17]: Plotting.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:18]: 0.064 secs elapsed.</span></span></code></pre></div>
<div class="inline-figure"><img src="sigminer_files/figure-html/unnamed-chunk-57-1.png" width="95%"></div>
<div class="sourceCode" id="cb46"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="fu"><a href="https://rdrr.io/pkg/sigminer/man/show_sig_bootstrap.html">show_sig_bootstrap_error</a></span><span class="op">(</span><span class="va">bt_result</span>, sample <span class="op">=</span> <span class="st">"TCGA-A8-A09G-01A-21W-A019-09"</span><span class="op">)</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:18]: Started.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:18]: Plotting.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:18]: 0.043 secs elapsed.</span></span></code></pre></div>
<div class="inline-figure"><img src="sigminer_files/figure-html/unnamed-chunk-58-1.png" width="95%"></div>
<div class="sourceCode" id="cb47"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="fu"><a href="https://rdrr.io/pkg/sigminer/man/show_sig_bootstrap.html">show_sig_bootstrap_stability</a></span><span class="op">(</span><span class="va">bt_result</span><span class="op">)</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:18]: Started.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:18]: Plotting.</span></span>
<span><span class="co">## ℹ [2021-12-04 23:51:18]: 0.037 secs elapsed.</span></span></code></pre></div>
<div class="inline-figure"><img src="sigminer_files/figure-html/unnamed-chunk-59-1.png" width="95%"></div>
<p>P values have been calculated under specified relative exposure cutoff (0.05 at default).</p>
</div>
</div>
</div>
  <div class="chapter-nav">
<div class="prev"><a href="prerequisite.html"><span class="header-section-number">2</span> Package prerequisite and installation</a></div>
<div class="next"><a href="analysis-supps.html"><span class="header-section-number">4</span> Other signature types</a></div>
</div></main><div class="col-md-3 col-lg-2 d-none d-md-block sidebar sidebar-chapter">
    <nav id="toc" data-toggle="toc" aria-label="On this page"><h2>On this page</h2>
      <ul class="nav navbar-nav">
<li><a class="nav-link" href="#basic-workflow"><span class="header-section-number">3</span> Mutational signature analysis basics</a></li>
<li>
<a class="nav-link" href="#data-input"><span class="header-section-number">3.1</span> Data input</a><ul class="nav navbar-nav">
<li><a class="nav-link" href="#vcf-as-input"><span class="header-section-number">3.1.1</span> VCF as input</a></li>
<li><a class="nav-link" href="#maf-as-input"><span class="header-section-number">3.1.2</span> MAF as input</a></li>
</ul>
</li>
<li>
<a class="nav-link" href="#tally-components"><span class="header-section-number">3.2</span> Tally components</a><ul class="nav navbar-nav">
<li><a class="nav-link" href="#the-most-common-96-components"><span class="header-section-number">3.2.1</span> The most common 96 components</a></li>
<li><a class="nav-link" href="#other-situations"><span class="header-section-number">3.2.2</span> Other Situations</a></li>
</ul>
</li>
<li>
<a class="nav-link" href="#de-novo-signature-discovery"><span class="header-section-number">3.3</span> de novo signature discovery</a><ul class="nav navbar-nav">
<li><a class="nav-link" href="#manual-signature-estimation-and-extraction"><span class="header-section-number">3.3.1</span> Manual signature estimation and extraction</a></li>
<li><a class="nav-link" href="#automatic-extraction"><span class="header-section-number">3.3.2</span> Automatic extraction</a></li>
</ul>
</li>
<li><a class="nav-link" href="#match-signatures"><span class="header-section-number">3.4</span> Match Signatures</a></li>
<li>
<a class="nav-link" href="#reference-signature-fitting"><span class="header-section-number">3.5</span> Reference signature fitting</a><ul class="nav navbar-nav">
<li><a class="nav-link" href="#fit-signatures-from-reference-signature-databasase"><span class="header-section-number">3.5.1</span> Fit signatures from reference signature databasase</a></li>
<li><a class="nav-link" href="#fit-custom-signatures"><span class="header-section-number">3.5.2</span> Fit custom signatures</a></li>
<li><a class="nav-link" href="#performance-comparison"><span class="header-section-number">3.5.3</span> Performance comparison</a></li>
<li><a class="nav-link" href="#estimate-exposureactivity-stability-by-bootstrapping"><span class="header-section-number">3.5.4</span> Estimate exposure/activity stability by bootstrapping</a></li>
</ul>
</li>
</ul>

      <div class="book-extra">
        <ul class="list-unstyled">
          
        </ul>
</div>
    </nav>
</div>

</div>
</div> <!-- .container -->

<footer class="bg-primary text-light mt-5"><div class="container"><div class="row">

  <div class="col-12 col-md-6 mt-3">
    <p>"<strong>Extract, Analyze and Visualize Mutational Signatures with Sigminer</strong>" was written by Shixiang Wang, PhD (Sun Yat-sen University Cancer Center), Xue-Song Liu, PhD (ShanghaiTech University). It was last built on 2022-08-29.</p>
  </div>

  <div class="col-12 col-md-6 mt-3">
    <p>This book was built by the <a class="text-light" href="https://bookdown.org">bookdown</a> R package.</p>
  </div>

</div></div>
</footer><!-- dynamically load mathjax for compatibility with self-contained --><script>
  (function () {
    var script = document.createElement("script");
    script.type = "text/javascript";
    var src = "true";
    if (src === "" || src === "true") src = "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.9/latest.js?config=TeX-MML-AM_CHTML";
    if (location.protocol !== "file:")
      if (/^https?:/.test(src))
        src = src.replace(/^https?:/, '');
    script.src = src;
    document.getElementsByTagName("head")[0].appendChild(script);
  })();
</script><script type="text/x-mathjax-config">const popovers = document.querySelectorAll('a.footnote-ref[data-toggle="popover"]');
for (let popover of popovers) {
  const div = document.createElement('div');
  div.setAttribute('style', 'position: absolute; top: 0, left:0; width:0, height:0, overflow: hidden; visibility: hidden;');
  div.innerHTML = popover.getAttribute('data-content');

  var has_math = div.querySelector("span.math");
  if (has_math) {
    document.body.appendChild(div);
    MathJax.Hub.Queue(["Typeset", MathJax.Hub, div]);
    MathJax.Hub.Queue(function() {
      popover.setAttribute('data-content', div.innerHTML);
      document.body.removeChild(div);
    })
  }
}
</script>
</body>
</html>
